I searched online, but couldn't find anything about how to stop page loading over a browser using selenium web-driver.

Any idea for the same?

  • Can you explain what you mean by 'stop page loading' ? – Phil Kirkham Feb 4 '13 at 18:51
  • 4
    he wants the page to stop loading... – squeemish Feb 4 '13 at 19:13

This might be useful.



JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return window.stop");
| improve this answer | |
  • The find element body did not work for me as it could not find the element until the page loaded. However the Javascript works beautifully – Adam Garner Aug 7 '17 at 10:28

If you are using firefox then you can set preference for default timeout:

fp = webdriver.FirefoxProfile()
fp.set_preference("http.response.timeout", 5)
fp.set_preference("dom.max_script_run_time", 5)
driver = webdriver.Firefox(firefox_profile=fp)


This will stop page load after 5 seconds.

| improve this answer | |
  • I get: Exception in thread "main" java.lang.IllegalArgumentException: dom.max_script_run_time must be == 0 || >= 30 So, minimum is 30 seconds or 0. – invzbl3 Aug 1 '19 at 14:16

If you want to simulate the browser's STOP button, this post should help you out https://stackoverflow.com/questions/5453423/how-to-stop-the-page-loading-in-firefox-programaticaly

| improve this answer | |
  • yeah! I have gone through that post earlier,but couldn't understand how to really write it... as that was shorthand code. can you help me on that? – CodeLover Feb 5 '13 at 18:10

There were a few possible solutions to this over on Stackoverflow on Stop browser load from selenium webdriver.

This included:

| improve this answer | |

Here is a function you may call to set the page load timeout you need.

| improve this answer | |
  • Link only answers are not encouraged. Please add the solution part of the link to your answer. – LittlePanda Apr 30 '15 at 11:43
  • 1
    Also, the link is dead. – Frank H. Feb 9 '17 at 11:57

I use three steps with chrome and it works:

  1. Navigate to "about:blank"
  2. Get element "body"
  3. On that element send keys "Esc"
| improve this answer | |

We can use windows.stop(); in order to stop the page loading. Try the below code:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.