Stop browser loading with selenium webdriver

My selenium webdriver goes to the page and waits for this page to finish loading. If 30 seconds time out and the script fails.

In any case, for the webdriver to stop loading the page after 30 seconds (for example, by pressing "x" in the browser)? This will prevent the failure of my driver.

I am using Chromedriver.

+4
source share
3 answers

This is exactly how I ran into this problem. I will use this path until chrome supports pageload .

I installed an extension in chrome called Stop load, and I set the stop to 5 seconds.

Then I installed 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 after 5 seconds, your extension will take care of this by killing it in 5 seconds.

In a sense, it works as implicit if you set the correct break time in the extension

+3
source

Try using this:

  driver.manage().timeouts().pageLoadTimeout(); 

Documentation:
Page load time

Also, as a hint, you cannot access the basic browser controls using Selenium WebDriver. If you want to do this, use tools like Sikuli if you are using Linux or AutoIt for Windows.

+1
source

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

 driver.execute_script("window.stop()") 
0
source

All Articles