python3.8.0怎么设置字体大小,如何设置python硒3.8.0的'driver.get'超时?

In selenium tests, you open a webpage using

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("whateverpage.org.com")

How can I set the timeout of this command for selenium version 3.8.0 and python 2.7.12?

解决方案

To set the time out for Page Loading you can induce the set_page_load_timeout(seconds).

set_page_load_timeout

Method Details

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.

Args

time_to_wait: The amount of time to wait

Usage

driver.set_page_load_timeout(3)

Example

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=1hotelTmpl")

print("URL successfully Accessed")

driver.quit()

except TimeoutException as e:

print("Page load Timeout Occured. Quiting !!!")

driver.quit()

Console Output

Page load Timeout Occured. Quiting !!!

Documentation

You can find a detailed discussion on pageLoadTimeout here pageLoadTimeout in Selenium not working

Deep Dive

As per Python 3.x if we don't handle the exception the following log messages are observed :

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值