【问题标题】:How to wait HTML element appear globally with Selenide?如何使用 Selenide 等待 HTML 元素全局出现?
【发布时间】:2020-01-16 02:33:47
【问题描述】:

我们有许多由 Selenide 编写的 e2e 测试。 为了避免在测试服务器中测试失败,我希望 selenide 等待 html 元素出现。

我知道一些像wait.until(...) 这样的脚本。但是,我不想修复所有的测试代码。

Selenide 是否有任何全局开关或设置? (详细点,希望选项制作cssselector等待)

【问题讨论】:

标签: java selenide


【解决方案1】:

this post解决了我的问题

Implicit Wait is the way to configure the WebDriver instance to poll the HTML DOM (DOM Tree) 
for a configured amount of time when it tries to find an element 
or find a group/collection of elements if they are not immediately available. 
As per the current W3C specification the default time is configured to 0. 
We can configure the time for the Implicit Wait any where within our script/program and can reconfigure it as per our necessity. 
Once we set Implicit Wait it will be valid for the lifetime of the WebDriver instance.

我认为隐式等待时间几乎是我预期的全局切换。

【讨论】:

    【解决方案2】:

    在执行任何操作之前,selenide 提供了查找条件的方法。 $("By Locator").shouldBe(Condition."Desired Condition").

    【讨论】:

      【解决方案3】:

      这个问题我可能迟到了。但是对于在硒等待方面仍需要帮助的任何人,我的回答可能仍然会有所帮助。

      对于 selenium,如果您有如下等待方法:

      element = (new WebDriverWait(driver, <timeOutForElement>))
        .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(<cssSelector>)));
      

      您可以使用 element = $(&lt;cssSelector&gt;).should(exist); 在 Selenide 中执行相同的操作

      对于

      element = (new WebDriverWait(driver, <timeOutForElement>))
        .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(<cssSelector>)));
      

      我们只选择element = $(&lt;cssSelector&gt;).shouldBe(visible);

      参考页Here

      【讨论】:

        猜你喜欢
        • 2017-03-30
        • 2016-05-09
        • 2013-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多