[英]Selenium Webdriver wait for url?
我有一个Selenium Webdriver脚本,用python编写,打开一个url;
def GotToURL(self):
#Go to url
driver.get("http://someurl.com")
#Prints url once it is finished loading
print driver.current_url
问题是每15个中有1个,网址不会完成加载。 因此,我想添加的是尝试运行该步骤的步骤
print driver.current_url
10秒钟,如果不起作用,请重新启动脚本。
任何想法?
在osx上运行Selenium Webdriver和python 2.7
我能想到的最佳选择是使用显式和隐式等待 。
例如,您可以像这样定义驱动程序
driver = webdriver.Ie() #note that I'm using IE
driver.set_page_load_timeout(10) #set the max to 10s
然后将您的操作放在try except语句中,指定TimeoutException。 你这样说,如果页面加载超过10秒,驱动程序必须抛出异常,然后你可以定义如何处理这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.