python - 单击贝宝“同意并继续”按钮时,.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')
我也试过 to_be_clickable
mainagree = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[@id='payment-submit-btn'][@data-
disabled='false']")).click()
它就像一半的时间一样工作,这让我很困惑,有时当它不起作用时我会收到这个错误
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (951, 965)
(会话信息:chrome=91.0.4472.27)
解决方案
解决方案对我来说似乎相对容易。只需等待确切的文本:
button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH,
"//button[contains(text(), 'Agree & Continue')]"
button.click()
或者,
//button[contains(text(), 'Agree & Continue')]
推荐阅读
- javascript - 数据表:突出显示与行中其他单元格不同的单元格
- git - 由于冲突,此分支无法重新设置基础
- java - 在特定位置初始化另一个数组时使用数组
- android - 如何为自定义按钮内的图像添加边距
- sql - 可以跨命名空间进行 SQL 查询吗?
- reactjs - Firebase,React:onAuthStateChanged 内的 Axios GET 请求导致渲染问题
- android - 为什么 ContentResolver 看不到其他应用添加的文件?
- python - 如何使用 twilio 在 whatsapp 上发送位置对象?
- c# - 从 SQL Server 读取/查看 Blazor pdf 文件
- html - 我想让我的标题像原来的 olx 网站一样。任何人都可以告诉我如何像原始图片一样拉伸搜索栏?