等到selenium java不起作用()

发布于 2025-01-22 00:47:32 字数 663 浏览 0 评论 0原文

我需要等到页面上显示某些元素。 我创建了使用wait.ultil(endureconconditions.visibilityofelementLocated())

public void waitForElementPresentBy(By locator) {
    try{
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    }catch (Exception e){
        Assert.fail("Element was not become visible");
    }
}

等待对象以下一步的方式初始化 - 我设置了300秒:

wait = new WebDriverWait(webDriver, 300);

但是这方法未正确执行。它不会等到我的元素可见。

当我添加thread.sleep(3000)时,它有所帮助。 但是如何等待元素不添加sleep()

I need to wait until some element will be displayed on page.
I have created method in which I have used wait.until(ExpectedConditions.visibilityOfElementLocated()):

public void waitForElementPresentBy(By locator) {
    try{
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    }catch (Exception e){
        Assert.fail("Element was not become visible");
    }
}

wait object was initialized in next way - I have set 300 seconds:

wait = new WebDriverWait(webDriver, 300);

But this method is not executed correctly. It does not wait until my element will be visible.

When I added Thread.sleep(3000), it helped.
But how to waiting for element not adding sleep()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2025-01-29 00:47:32

根据API文档 visibilityFelementLostocated(locator) 期望检查页面的DOM上存在元素并可见。可见性意味着该元素不仅显示大于0

。 EM> 方法几乎是经过证明的,并且是一种强大的机制,可以等待某个元素的可见性 。有点不清楚您为什么感觉到 ...它不会等到我的元素被看到... 。更多细节将帮助我们以更好的方式理解问题。

但是,这里考虑了有关的可见性,但不是对执行测试的用户的眼睛。

注意a :如果您使用 selenium4 您必须使用以下WebDriverWait符号:

wait = new WebDriverWait(webDriver, Duration.ofSeconds(300));

注释B :当您使用WebDriverWait时,请记住删除隐式等待 conplet。

As per the API documentation visibilityOfElementLocated(locator) is the expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

visibility_of_element_located() method is pretty much proven and a robust mechanism to wait for the visibility of a certain element. A bit unclear why you felt ...it does not wait until my element will be visible.... A bit of more details would have helped us to understand the issue in a better way.

However, here visibility is considered with respect to Selenium but not to eyes of the user executing the tests.

Note A: If you are using you have to use the following WebDriverWait notation:

wait = new WebDriverWait(webDriver, Duration.ofSeconds(300));

Note B: As you are using WebDriverWait remember to remove Implicit Wait conpletely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文