如何使用’预期条件’来检查python-selenium中的元素?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用’预期条件’来检查python-selenium中的元素?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1461字,纯文字阅读大概需要3分钟。
内容图文
我无法理解如何使用“预期条件”来检查元素的存在.鉴于this documentation,根本不清楚如何使用它.我试过以下代码
def _kernel_is_idle(self):
return EC.visibility_of_element_located((By.XPATH, '//*[@id="kernel_indicator_icon" and @title="Kernel Idle"]'))
用于检查元素的想法(可调用为类中的方法).有两件事没有任何意义:
>根据文档(我必须查找源代码!),此方法应该返回True或False.但是,它返回以下内容:
<selenium.webdriver.support.expected_conditions.visibility_of_element_located object at 0x110321b90>
>如果没有webdriver,这个功能如何工作?通常你总是有一个电话
driver.do_something()
但是对于’预期条件’,对于webdriver的引用是什么?
解决方法:
好像你差不多了.
Documentation明确说明如下:
class selenium.webdriver.support.expected_conditions.visibility_of_element_located(locator)
其定义为:
An 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. locator – used to find the element
returns the WebElement once it is located and visible
因此,当你提到:
return EC.visibility_of_element_located((By.XPATH, '//*[@id="kernel_indicator_icon" and @title="Kernel Idle"]'))
找到的WebElement返回如下:
<selenium.webdriver.support.expected_conditions.visibility_of_element_located object at 0x110321b90>
甚至Source Code也表示如下:
try:
return _element_if_visible(_find_element(driver, self.locator))
搜索失败时:
except StaleElementReferenceException:
return False
内容总结
以上是互联网集市为您收集整理的如何使用’预期条件’来检查python-selenium中的元素?全部内容,希望文章能够帮你解决如何使用’预期条件’来检查python-selenium中的元素?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。