无法通过selenium Web驱动程序中的xpath单击按钮

Unable click button by xpath in selenium webdriver

本文关键字:xpath 单击 按钮 驱动程序 Web selenium      更新时间:2023-09-26

这是我有的代码

<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")查找并单击该元素之前,需要切换该帧。

希望能有所帮助…:)