在Selenium Python绑定中设置页面加载超时 [英] Setting page load timeout in Selenium Python binding
问题描述
driver = webdriver.Firefox()
driver.get(' someebpage')
elm = WebDriverWait(driver,5).until(ExpectedConditions.presence_of_element_located((By.ID,'someelementID'))
elm.click()
它不起作用,因为Selenium等待driver.get()完全检索网页,现在我想写一个为driver.get()设置超时的代码,如:
driver.get('somewebpage')。timeout(5)
5秒后加载页面,程序流程继续进行,驱动程序.get()是否完全加载网页。
顺便说一下,我已经搜索了该功能我上面说过,并且遇到了:
Selenium WebDriver转到页面,而不用等待页面加载
但问题是上面的链接中的答案没有说什么关于Python
如何完成我正在寻找的未来?
python
当前问题中提到的问题的等效代码( Selenium WebDriver转到页面,而不用等待页面加载):
从selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('webdriver.load.strategy','unstable')
driver = webdriver.Firefox(profile)
和:
driver.set_page_load_timeout(5)
I am writing a bot using Python with Selenium module.When I open a webpage with my bot, since the webpage contains too many external sources than dom, it takes a lot to get all of the page loaded. I used the explicit and implicit waits to eliminate this problem since I just wanted a specific element to be loaded and not all of the webpage, it didn't work. The problem is If i run the following statement:
driver = webdriver.Firefox()
driver.get('somewebpage')
elm = WebDriverWait(driver, 5).until(ExpectedConditions.presence_of_element_located((By.ID, 'someelementID'))
elm.click()
It doesn't work since the Selenium waits for the driver.get() to fully retrieve the webpage and then, it proceeds further. Now I want to write a code that sets a timeout for driver.get(), Like:
driver.get('somewebpage').timeout(5)
Where the driver.get() stops loading the page after 5 secs and the program flow proceeds, whether the driver.get() fully loaded webpage or not.
By the way, I have searched about the feature that I said above, and came across there:
Selenium WebDriver go to page without waiting for page load
But the problem is that the answer in the above link does not say anything about the Python equivalent code.
How do I accomplish the future that I am searching for?
python
equivalent code for the question mentioned in the current question (Selenium WebDriver go to page without waiting for page load):
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('webdriver.load.strategy', 'unstable')
driver = webdriver.Firefox(profile)
and:
driver.set_page_load_timeout(5)
这篇关于在Selenium Python绑定中设置页面加载超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!