【问题标题】:Explicit Waits on a given action (error) - Selenium Webdriver显式等待给定操作(错误) - Selenium Webdriver
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    相关资源
    最近更新 更多