如何设置Selenium Python WebDriver默认超时? [英] How to set Selenium Python WebDriver default timeout?

查看:2340
本文介绍了如何设置Selenium Python WebDriver默认超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图找到一个很好的方法来设置Selenium Python WebDriver中命令执行延迟的最大时间限制。理想情况下,如下所示:

 $ $ b $ my_driver = my_driver.get('http://www.example.com')#当时间超过30秒时停止/抛出异常

会起作用。我找到了 .implicitly_wait(30),但我不确定它是否会导致所需的行为。





$ b

编辑
$ b $如果有用,我们特别使用WebDriver for Firefox。根据@ amey的回答,这可能是有用的:

  ff = webdriver.Firefox()
ff.implicitly_wait(10)#秒
ff.get(http:// somedomain / url_that_delays_loading)
myDynamicElement = ff.find_element_by_id(myDynamicElement)

但是,我不清楚隐式等待是否适用于 get

$ p
$ p


$ p


在python中,创建页面加载超时的方法是:

 

driver.set_page_load_timeout(30)

这会抛出 TimeoutExce ption ,当页面加载时间超过30秒时。


Trying to find a good way to set a maximum time limit for command execution latency in Selenium Python WebDriver. Ideally, something like:

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

would work. I have found .implicitly_wait(30), but I'm not sure if it results in the desired behavior.

In case it is useful, we are specifically using the WebDriver for Firefox.

EDIT

As per @amey's answer, this might be useful:

ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds
ff.get("http://somedomain/url_that_delays_loading")
myDynamicElement = ff.find_element_by_id("myDynamicElement")

However, it is not clear to me whether the implicit wait applies both to get (which is the desired functionality) and to find_element_by_id.

Thanks very much!

解决方案

In python, the method to create a timeout for a page to load is:

driver.set_page_load_timeout(30)

This will throw a TimeoutException whenever the page load takes more than 30 seconds.

这篇关于如何设置Selenium Python WebDriver默认超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆