python - 第二个按钮在 selenium python 中不起作用
问题描述
from selenium import webdriver
browser = webdriver.Chrome('C:/Users/linus/Desktop/chromedriver')
browser.get('Website')
searchBar = browser.find_element_by_id('a')
searchBar.send_keys('123456789')
button = browser.find_element_by_tag_name('button')
button.click()
我打开我的网站,有一个输入字段。我输入我的名字,然后单击验证。该网站等待来自我的手机的连接,但连接在大约 1 分钟后超时。当它超时时,会出现一个按钮,上面写着再试一次。
我的问题是当连接超时时,我无法让 python 脚本单击重试按钮,我总是必须手动进行。有没有办法解决这个问题。
解决方案
import time
# all your code above from below
searchBar = browser.find_element_by_id('a')
searchBar.send_keys('123456789')
## once it reaches this point
# wait 70 seconds to continue to script. its abit above your average delay
time.sleep(70)
try:
# try and click the button the pops up and click it
button = browser.find_element_by_tag_name('button')
button.click()
else:
button = browser.find_element_by_tag_name('button')
button.click()
不确定这是否会起作用,但在这方面的一些东西......
推荐阅读
- mysql - 如何在kafka jdbc连接源中过滤数据库中的表
- java - 在 Java / Kotlin / Android 中,如何在线性渐变的某个点获得颜色?
- c - 用 C 编写一个 lua_Reader 函数
- c# - 在同一类 c# 中的构造函数中调用构造函数并在同一构造函数中调用基构造函数
- javascript - 在 Reactjs 中导入带样式的无状态功能组件
- java - JavaFX 在自定义编辑单元格中请求焦点
- android - 计算 Map 中的元素个数
>? 通过它的钥匙 - django - Django:ManyToManyField 相关名称不起作用
- html - 在 Boostrap 4 中,如何防止表单标签对齐?
- c# - asp.net web 表单响应 csv 类型到 zip