gpt4 book ai didi

python - 如何设置python Selenium 3.8.0的 'driver.get'超时?

转载 作者:行者123 更新时间:2023-12-04 22:40:10 27 4
gpt4 key购买 nike

在 Selenium 测试中,您可以使用

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("whateverpage.org.com")

如何为 Selenium 版本 3.8.0 和python 2.7.12设置此命令的超时?

最佳答案

要将 time out 设置为Page Loading ,您可以导出 set_page_load_timeout(seconds)

set_page_load_timeout

方法细节

def set_page_load_timeout(self, time_to_wait):
"""
Set the amount of time to wait for a page load to complete
before throwing an error.

精氨酸
time_to_wait: The amount of time to wait

用法
driver.set_page_load_timeout(3)

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

driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.set_page_load_timeout(2)
try :
driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl")
print("URL successfully Accessed")
driver.quit()
except TimeoutException as e:
print("Page load Timeout Occured. Quiting !!!")
driver.quit()

控制台输出
Page load Timeout Occured. Quiting !!!

文献资料

您可以在 pageLoadTimeout 上找到有关 的详细讨论,pageLoadTimeout in Selenium not working

深潜

按照Python的 3.x,如果我们不处理异常,则会观察到以下日志消息:
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
(Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.2.9200 x86_64)

关于python - 如何设置python Selenium 3.8.0的 'driver.get'超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47694922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com