python - 在这种情况下,如何在 selenium 上选择更改的按钮
问题描述
我正在尝试等待“同意并继续”按钮出现并与 .click() 交互
该按钮基本上以“继续按钮”开始,然后变为“同意并继续”。
在“继续”按钮之前:
<button class="ppvx_btn___5-8-2" aria-live="assertive" id="payment-submit-btn" data-testid="submit-button-initial" data-disabled="true" xpath="1">Continue<span class="ppvx_btn--state__screenreader___5-8-2"></span></button>
在“同意并继续”按钮后:
<button class="ppvx_btn___5-8-2" aria-live="assertive" id="payment-submit-btn" data-testid="submit-button-initial" data-disabled="false" xpath="1">Agree & Continue<span class="ppvx_btn--state__screenreader___5-8-2"></span></button>
我试过的:
mainagree = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, "//button[@id='payment-submit-btn'][@data-
disabled='false']")).click()
print('clicked')
它有时会起作用,但并不一致。
有时,我认为它单击了上一个“继续”按钮,当它不起作用时,我收到以下错误消息:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (951, 965)
(会话信息:chrome=91.0.4472.27)
解决方案
该element click intercepted: Element is not clickable at point
问题可能是由几个问题引起的,因此我们无法知道您的情况到底发生了什么。
可能您应该使用invisibility_of_element_located
让其他一些元素消失,或者使用 JavaScript click 或只是添加一些延迟。
有关这一点的良好解释,请参见此处。
如果您的元素不在屏幕上,您应该滚动到它
这里是如何滚动的示例
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_id("my-id")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
推荐阅读
- python - 释放按钮后调用的 keyPressEvent
- c++ - 有没有一种优雅的方式来遍历 Clang AST 语句?
- sql - 如何在 SQL 中获取 JSON 数据的最后一个键的值
- magento2 - 如何从一个模块调用函数到另一个 Magento 2
- angular - 如何将数据从子组件传递到根组件
- oracle - 适用于 ORACLE 而不适用于 DB2 的 SQL
- python - 如何将 TreeView 中的文件再次保存为 json 文件?
- scrapy - 为网站使用 Scrapy Spider 结果
- javascript - 请求超时???如何使用 routerlink 导航到 3 个页面
- java - 在java中比较/获取2个具有相同键但顺序不同的json文件?