等到selenium java不起作用()
我需要等到页面上显示某些元素。 我创建了使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据API文档
visibilityFelementLostocated(locator)
期望检查页面的DOM上存在元素并可见。可见性意味着该元素不仅显示大于0。 EM> 方法几乎是经过证明的,并且是一种强大的机制,可以等待某个元素的可见性 。有点不清楚您为什么感觉到 ...它不会等到我的元素被看到... 。更多细节将帮助我们以更好的方式理解问题。
但是,这里考虑了有关硒的可见性,但不是对执行测试的用户的眼睛。
注意a :如果您使用 selenium4 您必须使用以下WebDriverWait符号:
注释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 selenium4 you have to use the following WebDriverWait notation:
Note B: As you are using WebDriverWait remember to remove Implicit Wait conpletely.