首页 > 解决方案 > 显式等待给定操作(错误) - Selenium Webdriver

问题描述

早上好家伙!

我使用 Selenium Webdriver (JAVA) 的自动化存在问题。首先,系统(接口)使用AJAX,好吗?!

我必须多次单击同一个按钮。此按钮保留相同的元素。

为了避免错误(ElementClickInterceptedException 和/或 StaleElementReferenceException),我最初添加了一个带有异常“elementToBeClickable”的 WebdriverWait。但是,即使等待,错误仍然存​​在。

然后我决定添加 FluentWait。我添加了异常,时间等,但也保留了错误。

我发现唯一可行的方法是著名的“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")));

有谁能够帮我?非常感谢您!

标签: javaseleniumselenium-webdriverautomationautomated-tests

解决方案


您能否连同您的问题一起上传应用程序的 html 源代码?还要检查该按钮元素是否在任何 iframe 标记内,如果是,则必须实现 driver.switchTo().frame(iFrame)。


推荐阅读