selenium TimeoutException:消息:python

时间:2016-03-21 08:24:26

标签: python selenium selenium-firefoxdriver request-timed-out

我有以下代码,并尝试使用selenium连接到itunesconnect

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

driver = webdriver.Firefox()

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

但我得到*** TimeoutException: Message:如下

*** TimeoutException: Message:
Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmp27vpUf/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
    at FirefoxDriver.prototype.findElement (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmp27vpUf/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmp27vpUf/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmp27vpUf/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/tmp27vpUf/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)

知道出了什么问题?

1 个答案:

答案 0 :(得分:2)

元素在iframe内,您需要先切换到它

driver.switch_to_frame('authFrame') # by frame id, can also be name or WebElement
element = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_id('appleId'))

并切换回来

driver.switch_to_default_content()