python selenium selenium.common.exceptions.StaleElementReferenceException 错误

标签 python selenium selenium-firefoxdriver

我有以下代码

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Firefox()

driver.get("https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa")
username = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_id('appleId'))
password = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_id('pwd'))

username.send_keys("xxxxxxxxxx.com")
password.send_keys("xxxxxxxx")

password.submit()

但我收到以下错误

password.submit()
File "/Users/.virtualenvs/itunes/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 84, in submit
    self._execute(Command.SUBMIT_ELEMENT)
  File "/Users/.virtualenvs/itunes/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
    return self._parent.execute(command, params)
  File "/Users/.virtualenvs/itunes/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "/Users/.virtualenvs/itunes/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, 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:9454)
    at Utils.getElementAt (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmpR5A61x/extensions/fxdriver@googlecode.com/components/command-processor.js:9039)
    at WebElement.submitElement (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmpR5A61x/extensions/fxdriver@googlecode.com/components/command-processor.js:12156)
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmpR5A61x/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at fxdriver.Timer.prototype.setTimeout/<.notify (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmpR5A61x/extensions/fxdriver@googlecode.com/components/command-processor.js:625)

有什么问题吗?

最佳答案

当您在密码字段中输入内容时,将呈现 DOM。您需要重新定位它

password = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_class_name('dots')) # class dots is added in the rendering
password.submit()

关于python selenium selenium.common.exceptions.StaleElementReferenceException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36126385/

相关文章:

java - Selenium 驱动程序无法加载某些页面的所有元素

java - AssertEquals 不会停止测试

java - 验证选择元素

java - selenium 中的desire 功能和Firefox 选项之间的主要区别是什么

java - Selenium WebDriver + Java - 如何为 Firefox 配置代理设置?

python - Pandas - 相当于 pandas 查询中的 str.contains()

python - 如何获取超过1000?

python - 为什么我无法安装 Cassandra 驱动程序

Python Mock - 模拟几个打开

testing - 测试时在哪里可以看到 firefoxdriver selenium 启动的内容?