Selenium错误在页面的最后

时间:2014-05-18 11:55:05

标签: python selenium

我已经使用selenium python编写了这段代码,因此解析网页(动态加载) 它会一直持续到最后,然后在“加载更多”时停止。按钮不再可点击。

 wait=WebDriverWait(driver,50) 
 wait.until(EC.element_to_be_clickable((By.ID, 'bottomPager'))) while
 EC.element_to_be_clickable((By.ID,'bottomPager')):
     driver.find_element_by_xpath('.//div[@id="bottomPager"]').click()
     if not driver.find_element_by_id('bottomPager').is_enabled():
        break
     wait.until(EC.element_to_be_clickable((By.ID,'bottomPager')))

但是当它到达页面末尾时我收到错误

Traceback (most recent call last):   File "python_org_search2.py", line 24, in <module>
    driver.find_element_by_xpath('.//div[@id="bottomPager"]').click()   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 60, in click
    self._execute(Command.CLICK_ELEMENT)   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 370, in _execute
    return self._parent.execute(command, params)   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 166, in execute
    self.error_handler.check_response(response)   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: u'unknown error: Element is not clickable at point (643, 628)\n  (Session info: chrome=34.0.1847.137)\n  (Driver info: chromedriver=2.9.248304,platform=Linux 3.13.0-24-generic x86_64)'

代码需要进行哪些更改才能纠正?

1 个答案:

答案 0 :(得分:0)

根据我的经验,只有在使用带有Selenium的Chrome驱动程序时才会出现此例外情况。你可以使用Firefox吗? (我相信Firefox是通过Selenium进行webdriver调用的主要浏览器。)

driver = webdriver.Firefox() 

那应该清除这个例外。

(您可以在this site获得可移植版本的Firefox。)