python - Selenium clicks a link just once, calling click() another time returns error -
i'm new selenium , managed write these codes. want scrap data on tables clicking '>' link @ bottom right. first click works next 2 don't. missing? thanks.
# coding: utf-8 selenium import webdriver selenium.webdriver.common.by import browser = webdriver.firefox() browser.get('http://s.cafef.vn/lich-su-giao-dich-hsg-1.chn') next_page_link = browser.find_element_by_partial_link_text('>') next_page_link.click() next_page_link = browser.find_element_by_partial_link_text('>') next_page_link.click() next_page_link = browser.find_element_by_partial_link_text('>') next_page_link.click()
here exception
traceback (most recent call last): file "cafef.py", line 13, in <module> next_page_link.click() file "/usr/local/lib/python2.7/dist-packages/selenium-2.40.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 59, in click self._execute(command.click_element) file "/usr/local/lib/python2.7/dist-packages/selenium-2.40.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 369, in _execute return self._parent.execute(command, params) file "/usr/local/lib/python2.7/dist-packages/selenium-2.40.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 164, in execute self.error_handler.check_response(response) file "/usr/local/lib/python2.7/dist-packages/selenium-2.40.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 164, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.staleelementreferenceexception: message: u'element no longer attached dom' ; stacktrace: @ fxdriver.cache.getelementat (resource://fxdriver/modules/web_element_cache.js:7613) @ utils.getelementat (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:7210) @ fxdriver.preconditions.visible (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:8223) @ delayedcommand.prototype.checkpreconditions_ (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:10861) @ delayedcommand.prototype.executeinternal_/h (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:10878) @ delayedcommand.prototype.executeinternal_ (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:10883) @ delayedcommand.prototype.execute/< (file:///tmp/tmpidosdw/extensions/fxdriver@googlecode.com/components/command_processor.js:10825)
the second next_page_link.click()
call occurring before browser has loaded next page. add wait.until ec.element_to_be_clickable:
from selenium import webdriver import selenium.webdriver.support.ui ui selenium.webdriver.common.by import import selenium.webdriver.support.expected_conditions ec import contextlib contextlib.closing(webdriver.firefox()) browser: browser.get('http://s.cafef.vn/lich-su-giao-dich-hsg-1.chn') wait = ui.webdriverwait(browser, 10) in range(3): next_page_link = wait.until( ec.element_to_be_clickable((by.partial_link_text, '>'))) next_page_link.click()
Comments
Post a Comment