简体   繁体   中英

Selenium : Stop page loading

I am using Selenium to test a bunch of URLs. But some of those are not valid and the browser may take quite a lot of time to stop loading.
The set_page_load_timeout( ) works well and will continue the execution of the code if the timeout has been reached but the next URL won't be tested until the browser has finished with its previous work...
I also tried to send a Javascript code ( window.stop() ) but it does not work until the page has been loaded.

Is there any proper way to do this ? If not, I will try any proposed solution.

If I understand correctly that by "they're not valid" you mean they may not exist, why not try:

 try {
     URL myURL = new URL("http://test.com/");
     URLConnection myURLConnection = myURL.openConnection();
     myURLConnection.connect(); 
}  catch (MalformedURLException e) {  }  
catch (IOException e) {    //end test }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM