这是我的代码
<button type="button" id="B-New" data-sap-ui="B-New" title="Add New Order" role="button" aria-disabled="false" tabindex="0" class="sapUiBtn sapUiBtnNorm sapUiBtnS sapUiBtnStd">Add</button>
xpath
为 "//*[@id='B-New']"
我试图单击该按钮,但无法单击。
我已经使用了xpath,ID类名一切,但无法点击。 这就是我正在使用的
driver.findElement(By.xpath("//*[@id='B-New']")).click()
请帮忙。
我也使用过javascript
jse.executeScript("document.getElementById('B-New').click()");
但它也不起作用。
最佳答案
您应该尝试使用 WebDriverWait
等待元素可见并启用单击,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.elementToBeClickable(By.id("B-New")));
el.click();
注意:- 如果此元素位于任何 frame
内,则需要在使用 driver.switchTo().frame("frame name or id")
查找并单击该元素之前切换该框架。
希望有帮助..:)
关于javascript - 无法在 selenium webdriver 中通过 xpath 单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38535003/