【问题标题】:Is there any way for waiting an element while other test steps are running with selenium?有没有办法在其他测试步骤使用硒运行时等待元素?
【发布时间】:2022-12-25 06:40:47
【问题描述】:

如果元素出现或不出现,我如何检查 30 秒?

我想在查找特定元素时跳过其他步骤,如果该元素出现我想单击。

有时该元素会在 2 秒或 10 秒后弹出(例如另一个页面已打开),我不想等待找到该元素。

我试过以下方法,但如果元素没有出现,测试将失败:

driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
MyLocator.click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //turn default

【问题讨论】:

    标签: java selenium selenium-webdriver automated-tests cucumber


    【解决方案1】:

    我认为您应该阅读有关 Explicit Wait 的内容。

    Selenium 中的 Explicit Wait 用于告诉 Web Driver 在抛出“ElementNotVisibleException”异常之前等待特定条件(Expected Conditions)或超过最大时间。

    例如:

    WebDriverWait wait = new WebDriverWait(Scenario1Test.driver, 30); 
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(locator);
    element.click()
    

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 2021-06-13
      • 2010-12-05
      • 2011-12-08
      相关资源
      最近更新 更多