等待使用Selenium Webdriver的元素 [英] Wait for an element using Selenium webdriver

查看:141
本文介绍了等待使用Selenium Webdriver的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

等待元素出现在网页上的最佳方法是什么?我已经读到我们可以使用隐式等待和函数,例如webdriverwait,fluentwait等,最后但不是最不重要的thread.sleep()...我使用最多但想要完全停止使用的

What is the best way to wait for an element to appear on a web page? I have read that we can use implicit wait and functions like webdriverwait, fluentwait etc and last but not the least thread.sleep()...which i use the most but want to stop using at all.

我的情况:

用户登录到网站...网站检查凭据并以覆盖图的形式(一种弹出窗口,但没有单独的窗口)向用户提供要约.我需要验证叠加层上的文字. 用户登录和显示叠加层之间存在时间间隔.什么是最好的方法,以便硒只等到元素不可见为止.由于叠加层不是单独的页面而是主页的一部分,因此隐式等待根本不起作用.

User logs in to a website...website checks the credentials and provides an offer to the user in the form of an overlay (kind of popup but not a separate window). I need to verify text on the the overlay. There is a time gap between user signing in and the overlay getting displayed. what is the best approach so that selenium waits only till the time the element is not visible. As the overlay is not a separate page but part of the main page, implicit wait does not work at all.

欢迎所有建议...:)

All suggestions are welcome...:)

推荐答案

您可以等待元素的出现如下所示:

You could wait for the presence of the element to appear as follows:

new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("someId")));

这篇关于等待使用Selenium Webdriver的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆