java - 显式等待给定操作(错误) - Selenium Webdriver

标签 java selenium selenium-webdriver automation automated-tests

大家早上好!

我在使用 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/

相关文章:

java - 在 Hadoop 中使用 DBOutputFormat

java - 有没有办法在使用 maven-jlink-plugin 的同时添加 maven 依赖项?

python - 来自 python selenium 脚本的回溯错误(间歇性工作)

java - 无法在 selenium Web 驱动程序中使用 Javascript 设置选择值

java - build().perform() 和 Perform() 之间有什么区别

java - Windows构建器 : How to draw a component when press a button?

java - 限制子类中的函数调用

java - selenium webdriver 中的元素不再附加到 DOM 错误

selenium - 使用带有 127.0.0.1 的内容脚本和带有 Firefox 插件的自定义端口

c# - jwplayer getDuration 在 chrome 控制台中有效,但在 C# 中与 IJavaScriptExecutor 无效