試圖找到一種在Selenium Python WebDriver中爲命令執行延遲設置最大時間限制的好方法。理想情況下,像這樣:如何設置Selenium Python WebDriver默認超時?
my_driver = get_my_driver()
my_driver.set_timeout(30) # seconds
my_driver.get('http://www.example.com') # stops/throws exception when time is over 30 seconds
會工作。我發現.implicitly_wait(30)
,但我不確定它是否會導致所需的行爲。
如果有用,我們特別使用Firefox的WebDriver。
編輯
按@ amey的答案,這可能是有用的:
ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds
ff.get("http://somedomain/url_that_delays_loading")
myDynamicElement = ff.find_element_by_id("myDynamicElement")
但是,我不清楚隱含的等待是否同時適用於get
(即所需功能)和find_element_by_id
。
非常感謝!
我看了一下源代碼的功能。 python綁定很模糊。但對於C#,'ImplicitlyWait'只適用於'FindElement/FindElements'(對Java相同)。來源:[1](https://code.google.com/p/selenium/source/browse/dotnet/src/WebDriver/ITimeouts.cs#48)[2](https://code.google.com/ p/selenium/issues/detail?id = 5092) –
謝謝。如果您有興趣,請參閱下面的答案。 –