python - 告诉脚本等到按钮可点击?
问题描述
我正在用 Selenium (Python) 编写脚本,但我遇到了禁用单击按钮的问题。该按钮仅在表单完成后才变为活动状态。
<button type="submit" class="pm_button primary large humanVerification-completeSetup-create" ng-disabled="model.emailCodeVerification === '' && model.captcha_token === false && model.smsCodeVerification === ''" translate="" translate-context="Action" disabled="disabled">Complete setup</button>
这是按钮 HTML 部分。现在按钮看起来像这样:
按钮图片 http://prntscr.com/pl4u96
如您所见,它不可点击。仅当验证码或任何其他类型的验证完成时,该按钮才会激活。现在我唯一的要求是在 Button 变为活动状态时检测它。
<button type="submit" class="pm_button primary large humanVerification-completeSetup-create" ng-disabled="model.emailCodeVerification === '' && model.captcha_token === false && model.smsCodeVerification === ''" translate="" translate-context="Action">Complete setup</button>
这是验证码或其他类型验证完成后的代码。验证完成后,第一行代码中的部分disabled="disabled"
被完全删除。我真的对如何检测它有 0 个想法,但我未能找到一个好的解决方案。
解决方案
诱导WebDriverWait
并等待element_to_be_clickable
()
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='pm_button primary large humanVerification-completeSetup-create'][text()='Complete setup']"))).click()
您需要导入以下内容。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
推荐阅读
- vb.net - 在vb.net中使用Like可以使用一系列负数和正数进行模式匹配吗
- postgresql - Postgresql sql脚本执行
- unity3d - 如何修复漆黑的自身阴影?
- google-chrome-devtools - 如何通过 chrome devtools 模拟设备转动
- javascript - 在 for 循环中嵌套的 ajax 函数调用
- java - 引起:org.xml.sax.SAXParseException;行号:5;列号:42;元素类型“id”的内容不完整,
- python-3.x - 如何在任何字符之后或之前立即从字符串中删除 + 和 - 符号,而不是来自 python3 中的其他位置
- php - 如何从 sql 中的对象中删除空格以使用 where 检查某些条件
- javascript - 有没有办法使用js检查服务器上的文件是否存在
- apache-kafka - kafka 流实例上的状态存储和分区的混合