我有以下代码
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/