python - 使用 Python 在 Selenium 中等待 elementID 或简单警报
问题描述
在尝试自动化 Selenium 和 python 中的任务时,我正在构建等待语句以查找元素或警报。我知道我错过了一些东西。
单击元素后,结果将是一个带有特定按钮的新页面(具有已知的“buttonID”),或者将生成一个简单的警报。我想捕捉这些事件中的任何一个并采取行动。
我可以等待按钮或警报:
driver.find_elements(By.ID,"buttonID")
和
expected_conditions.alert_is_present()
我可以成功地结合使用寻找两个元素
WebDriverWait(driver,10).until(
lambda driver: driver.find_elements(By.ID,"buttonID1) or driver.find_elements(By.ID,"buttonID2"))
)
但是,我在构建结合 find_elements 和 expected_conditions 的等待时遇到问题。基本上我正在尝试:
If buttonID is present:
Do X
If a simple alert is present:
Do Y
包装它以尝试捕获任何超时。
解决方案
推荐阅读
- python - Python:比较同一CSV中的多列
- javascript - React Native - 我可以将状态对象从父组件传递给子组件吗?
- javascript - How to just initialize the record without trigger "validateline" function in SuiteScript?
- mysql - 图像值为 NULL Mysql blob
- javascript - 在反应中通过 Deeplink POST 数据和重定向
- bash - 如何在 bash 脚本中正确处理 .js 扩展名?
- angular - 如何将角度数据表 td 元素从 {{element[column]}} 更改为输入表单字段
- dev-c++ - 在 Dev C++ 中更改输出目录
- android - 构建完成并运行,但在类 android 上显示错误
- apache-spark - 计算 Spark DataFrame 中每一列的核密度