【问题标题】:Selemium Webdriver: Loop not workingSelenium Webdriver:循环不起作用
【发布时间】:2018-12-30 20:34:00
【问题描述】:

运行代码时

 def extract():
    driver = webdriver.Firefox()
    driver.get('http://example.com/')

    while True:
        elm = driver.find_element_by_link_text(">>").click()
        elm.click()

if __name__ == '__main__':
    extract()

页面加载并单击下一个按钮(链接)并加载下一页, 新加载的页面也有相同的链接按钮,但它没有点击 并且,

出现错误:

Traceback (most recent call last):
  File "C:\Users\Admin\sel\click_next.py", line 14, in <module>
    extract_top_news()
  File "C:\Users\Admin\sel\click_next.py", line 11, in extract_top_news
    elm.click()
AttributeError: 'NoneType' object has no attribute 'click'

这是我试图点击的链接按钮

<li>
<a href='http://example.com/page.php?page=2'>&gt;&gt;</a>
</li>

我错过了什么!

【问题讨论】:

    标签: selenium automation geckodriver


    【解决方案1】:

    你确实喜欢双击,因为:

            elm = driver.find_element_by_link_text(">>").click()
            elm.click()
    

    就像

    driver.find_element_by_link_text(">>").click().click()
    

    所以只需删除第一个 .click()

    【讨论】:

      猜你喜欢
      • 2012-04-22
      • 2018-01-22
      • 2018-09-30
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多