【问题标题】:Selenium WebDriver Wait until ClickSelenium WebDriver 等到点击
【发布时间】:2020-11-26 12:22:01
【问题描述】:

我的代码有问题。

我需要等待 3 秒,然后点击关注按钮。

此代码在网站加载后立即单击“关注”按钮。

for follow in accounts_scrapped:
    driver.get(follow)

    try:
        follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']").click()
        print("found follow button")
        follow_button.click()
        print("followed")

    except:
        print("already followed this account. Going to next one")
        continue

【问题讨论】:

  • 使用time.sleep(3)?
  • 没有改变任何东西。
  • 您点击了两次按钮? follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']").click() 末尾有 .click()
  • 然后你就完成了follow_button.click()
  • 哎呀,我把它弄错了。我想点击一次,但不是立即。

标签: python-3.x selenium webdriver


【解决方案1】:

像这样调试你的代码,这可能有助于找出问题所在

for follow in accounts_scrapped:
    driver.get(follow)
    try:
        follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']")
        time.sleep(3)
        print('0 seconds letf')
        follow_button.click()
        print("followed")
    except Exception as e :
        print(e)
        print("already followed this account. Going to next one")
        continue

print(e) 将打印错误

【讨论】:

  • 你是说它不等待 3 秒吗?也许您在代码中的其他地方点击了它?
  • 我总是收到消息“已经关注此帐户。转到下一个”
  • 这意味着 try 块有一个错误,所以它移动到 except
  • print(e) 打印了什么?
  • 我理解的 time.sleep(3) 等待 3 秒,直到出现下一页。但是在这种情况下,当网站的每个页面出现时,它会立即再次单击“关注”按钮。
猜你喜欢
  • 2012-03-26
  • 2018-02-19
  • 2017-06-07
  • 2019-03-17
  • 2013-02-06
  • 2011-10-03
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多