python - Selenium Webdriver Python - 检查元素是否可见/检测到/存在
问题描述
我想检查 Selenium Web 驱动程序对于以下 XPath 是否可见/存在/检测到元素:
//*[@data-animate-modal-popup="true"]
每当该元素可见/存在/检测到时,是否有任何 Selenium 函数返回 TRUE 或 FALSE?
上次我使用以下 IF - Else
phone_number_invalid = driver.find_element_by_xpath('//*[@data-animate-modal-popup="true"]')
if phone_number_invalid:
code here .....
find_element_by_xpath
每当找不到元素时,它总是会引发错误。只要元素可见/存在/检测到,我只想获得 TRUE 或 FALSE。
谢谢你。
解决方案
- 为方便起见,您为什么不使用扩展程序。
- 使用铬:
- 使用“Xpath helper”检查元素:
https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en
- 使用“Xpath finder”查找元素:
https://chrome.google.com/webstore/detail/xpath-finder/ihnknokegkbpmofmafnkoadfjkhlogph?hl=en
推荐阅读
- javascript - 如何获取兄弟元素的内部html文本
- node.js - 如何切换或更改 Input.ChoiceSet 以响应其他 Input.ChoiSet 值?
- reactjs - 如何在 Antd 中使用动态表单嵌套
- javascript - 追加选择
- javascript - Firebase - 无法获取文档,因为客户端离线(v9 升级)
- mongodb - 我如何在聚合猫鼬中进行排序计算
- flutter - pub.dev 不接受颤动格式
- concurrency - pfSense 企业防火墙测试
- qt - 如何将组件导入 QtQuickDesigner?
- active-directory - Nextcloud 通过 LDAP 使用 Samba