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