selenium(python)引发StaleElementReferenceException,不会继续下载所有webdriver.find_elements_by_partial_link_文本()

2024-05-08 21:59:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用seleniumbindings for python下载页面上包含字符串“VS”的所有链接。问题是列表中的第二项不是有效的网页(返回404错误),如果我手动单击断开的链接,它会返回:

error.html - 404 error page does not exist.

如果我运行下面的代码,就会引发一个错误。在

^{pr2}$

错误:

Traceback (most recent call last):
  File "C:\Users\lskrinjar\Dropbox\work\preracun\src\web_data_mining\get_files_from_web.py", line 79, in <module>
    url = link.get_attribute("href")
  File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 93, in get_attribute
    resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
  File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 385, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 173, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up
Stacktrace:
    at fxdriver.cache.getElementAt (resource://fxdriver/modules/web-element-cache.js:8329:1)
    at Utils.getElementAt (file:///c:/users/lskrin~1/appdata/local/temp/tmppsn7tm/extensions/fxdriver@googlecode.com/components/command-processor.js:7922:10)
    at WebElement.getElementAttribute (file:///c:/users/lskrin~1/appdata/local/temp/tmppsn7tm/extensions/fxdriver@googlecode.com/components/command-processor.js:11107:31)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/lskrin~1/appdata/local/temp/tmppsn7tm/extensions/fxdriver@googlecode.com/components/command-processor.js:11635:16)
    at fxdriver.Timer.prototype.setTimeout/<.notify (file:///c:/users/lskrin~1/appdata/local/temp/tmppsn7tm/extensions/fxdriver@googlecode.com/components/command-processor.js:548:5)

Tags: inpyegglibpackagesseleniumlinejs