【问题标题】:Second button wont work in selenium python第二个按钮在 selenium python 中不起作用
【发布时间】:2020-05-05 10:44:47
【问题描述】:
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 脚本单击重试按钮,我总是必须手动进行。有没有办法解决这个问题。

【问题讨论】:

  • 我不明白问题。显示有问题(不在评论中)的真实 URL,以便我们可以看到问题。如果您收到错误消息,请也显示它。

标签: python selenium google-chrome selenium-webdriver automation


【解决方案1】:
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()

不确定这是否会起作用,但有些东西...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-04
    • 2013-06-19
    • 2021-06-03
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多