Reproduced Python & Selenium--page load time is too long & start specified FF

Source: Internet
Author: User
Tags set time

Original link: https://my.oschina.net/u/2344787/blog/400507?p={{page}} 1. Selenium Webdriver The Get method will wait until the page has finished loading before executing, but if the load time is too long it will cause subsequent operations to fail.

For example: Get Autohome page will wait for a long time, in fact, the basic elements of the page has been loaded, can be used for subsequent operations

The time can be set by the Set_page_load_time() method,

Then catch the timeout exception and stop the page load by executing JavaScript window.stop ()

1  fromSelenium.common.exceptionsImporttimeoutexception2 3StartTime =time.time ()4 Print "start time is:%0.3f"%StartTime5Driver =Webdriver. Firefox ()6 #set page load limit time7Driver.set_page_load_timeout (30)8 Driver.maximize_window ()9 Ten Try: OneDriver.get ('http://www.autohome.com.cn/') A excepttimeoutexception: -     Print 'Time out after seconds when loading page'   -Driver.execute_script ('window.stop ()')#when the page load time exceeds the set time, by executing JavaScript to stop loading, you can perform subsequent actions
2. Use the specified FF to create the driver
1  from Import firefoxbinary 2 MYFF = firefoxbinary ('/root/bobo/firefox/firefox-bin') 3 Driver = Webdriver. Firefox (FIREFOX_BINARY=MYFF)

Reproduced Python & Selenium--page load time is too long & start specified FF

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.