1

I am using seleninum web driver in c# and facing a weird problem. While automating i encountered a problem where page is continuously loading although DOM content has been loaded. Now i have now way to go forward until it does not stop, that why driver throws timeout exception. So, I need to know is there any way to stop page load from webdriver.

I have googled but no luck.

Siraj Hussain
  • 79
  • 2
  • 11

1 Answers1

0

You can do two things. Use Actions class press ESC key to stop the page from loading, Code shown bellow:

Actions actions = new Actions(Driver);
actions.SendKeys(Keys.Escape);

Or User JavaScriptExecutor to do the samething:

((IJavaScriptExecutor)Driver).ExecuteScript("return window.stop();");
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • @Saifur you might need to call `stop`: `((IJavaScriptExecutor)Driver).ExecuteScript("window.stop();");` – alecxe Aug 07 '15 at 17:25
  • I have tried above both but the problem is selenium will not proceed next command until page is loading. – Siraj Hussain Aug 07 '15 at 17:27
  • @SirajHussain Explain the result with StackTrace and stuff like that. I use it for testing and works for me – Saifur Aug 07 '15 at 17:49
  • Siraj Hussain is right in that this never works right after the statement webdriver.Navigate().GoToUrl("something"); and the page is still loading. Please refer to my answer at http://stackoverflow.com/questions/40012586/how-to-stop-loading-page-in-selenium-webdriver-when-an-element-is-already-presen – Silent Sojourner Jan 23 '17 at 17:01