大家早上好!
我在使用 Selenium Webdriver (JAVA) 进行自动化时遇到问题。 首先,系统(界面)使用AJAX,好吗?!
我必须多次单击同一个按钮。此按钮保留相同的元素。
为了避免错误(ElementClickInterceptedException 和/或 StaleElementReferenceException),我最初添加了一个带有异常“elementToBeClickable”的 WebdriverWait。 然而,即使这样等待,错误仍然存在。
然后我决定添加 FluentWait。我添加了异常(exception)、时间等,但也保留了错误。
我发现唯一有效的替代方案是著名的“Thread.sleep”(400ms)。
但我不想将 thread.sleep 添加到我的代码中,因为我发现这是一个不好的做法。
有人有什么想法吗?
下面是一些代码片段。
命令: driver.findElement(By.xpath("//tr[1]/td[8]/button"))。单击();已使用等待:
1:
wait.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));
2:
wait.until (ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath ("// tr / td [8] / button")));
3:
.withTimeout (10, TimeUnit.SECONDS)
.pollingEvery (1, TimeUnit.SECONDS)
.ignoring (NoSuchElementException.class)
.ignoring (StaleElementReferenceException.class)
.ignoring (ElementClickInterceptedException.class);
waitFluent.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));
有人可以帮我吗? 预先非常感谢您!
最佳答案
您能否上传该应用程序的 html 源代码以及您的问题?还要检查该按钮元素是否位于任何 iframe 标记内,如果是,则必须实现 driver.switchTo().frame(iFrame)。
关于java - 显式等待给定操作(错误) - Selenium Webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57924116/