Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop browser load from selenium webdriver

My selenium webdriver goes to a page and waits for that page to finish loading. If 30 seconds pass it times-out and the script fails.

Is there anyway to have the webdriver stop the page loading after 30 seconds(like pressing the 'x' on the browser)? This will prevent my driver from timing out.

I'm using Chromedriver.

like image 324
Francis Snipe Avatar asked Apr 05 '13 12:04

Francis Snipe


2 Answers

This is the way I came across this issue. I will be using this way until chrome supports pageload.

I installed an extension in chrome called Stop load and I set 5 secs stop load.

Then I initiated my driver with the default setting -

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir="+System.getProperty("user.home")+"\\AppData\\Local\\Google\\Chrome\\User Data"));
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver(capabilities); 

if the page in chrome does not load in 5 secs, your extension will take care of it by killing it in 5 Seconds.

In a way it works like a implicitwait if you set the proper stop load time in the extension

like image 99
Vijay Avatar answered Oct 26 '22 18:10

Vijay


You can stop page loading in Ruby using JavaScript function window.stop() and method Selenium::WebDriver::Driver#execute_script:

driver.execute_script("window.stop()")
like image 35
Arup Rakshit Avatar answered Oct 26 '22 17:10

Arup Rakshit