When we do automated testing, when we open a page with the Get method, we wait until the page is fully loaded to perform subsequent operations.
Sometimes the elements we need are loaded, and some JS is not loaded, resulting in a long load time, which undoubtedly increases the time for automated testing.
For this situation, you can set the time-out by using the set_page_load_timeout (seconds) method, and then catch the time-out exception before continuing.
#Encoding=utf-8Import Time fromSeleniumImportWebdriver fromSelenium.common.exceptionsImporttimeoutexceptionImportUnitTestclassVisiturl (unittest. TestCase):defsetUp (self): Self.driver= Webdriver. Ie (Executable_path ="E:\\iedriverserver") defTest_visiturl (self): Visiturl="http://www.google.com" #limit page load times to 3 secondsSelf.driver.set_page_load_timeout (3) Try: Self.driver.get (Visiturl)excepttimeoutexception:PrintU'page load timed out!' #when the page load time exceeds the set time, stop the download by executing JavaScript, and then proceed with the subsequent operationSelf.driver.execute_script ('window.stop ()') Time.sleep (2) defTearDown (self): Self.driver.quit ()if __name__=='__main__': Unittest.main ()
Selenium Common API (iv) Setting the GET method maximum load time