繁体   English   中英

Selenium webdriver与python-如果加载太长时间如何重新加载页面?

[英]Selenium webdriver with python- how to reload page if loading takes too long?

driver = webdriver.Firefox()               #opens firefox
driver.get("https://www.google.com/")      #loads google

如果加载谷歌需要太长时间,如何让它关闭浏览器并从头开始代码?

通过set_page_load_timeout()设置页面加载超时并捕获TimeoutException

from selenium import webdriver
from selenium.common.exceptions import TimeoutException

driver = webdriver.Firefox()
driver.set_page_load_timeout(10)
while True:
    try:
        driver.get("https://www.google.com/")
    except TimeoutException:
        print "Timeout, retrying..."
        continue
    else:
        break

另请参阅: 如何设置Selenium Python WebDriver默认超时?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM