【发布时间】:2020-01-15 08:36:39
【问题描述】:
大家早上好!
我在使用 Selenium Webdriver (JAVA) 进行自动化时遇到问题。 首先,系统(接口)使用AJAX,好吗?!
我必须多次点击同一个按钮。此按钮保留相同的元素。
为了避免错误(ElementClickInterceptedException 和/或 StaleElementReferenceException),我最初添加了一个带有异常“elementToBeClickable”的 WebdriverWait。 但是,即使等待,错误仍然存在。
然后我决定添加 FluentWait。我添加了异常、时间等,但也保留了错误。
我发现唯一可行的方法是著名的“Thread.sleep”(400 毫秒)。
但我不想将 thread.sleep 添加到我的代码中,因为我觉得这是一种不好的做法。
有人有什么想法吗?
下面是一些代码sn-ps。
命令: 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?
-
@KunduK,我不明白,对不起!你想要什么?
标签: java selenium selenium-webdriver automation automated-tests