ashish bandiwar
ashish bandiwar

Reputation: 404

How to prevent page from reload using selenium web driver or using Javascript?

Below options are not working. Are there any other options to try with in selenium c# or using JavaScript?

Tried with below statements but still no luck. driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE"); and driver.execute_script("window.stop();")

driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE"); and driver.execute_script("window.stop();")

Want to stop reload of a web page.

Upvotes: 1

Views: 4764

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193208

stop()

The Window stop() Method stops window loading and is the same as clicking on the browser's stop button.


Example Usage

  • Python:

    driver.execute_script("window.stop();");
    
  • Java:

    ((JavascriptExecutor)driver).executeScript("window.stop();");
    
  • C#:

    ((IJavaScriptExecutor)driver).ExecuteScript("window.stop();");
    

Note: Because of the script execution, this method cannot interrupt its parent document's loading, but it will stop its images, new windows, and other still-loading objects.

Upvotes: 2

Related Questions