0

I am automating few test cases on a webpage, but the problem is when this page opens it takes 10-15 seconds to come to ready state. So when I call webDriver.get() method, it waits until page state becomes ready and doesn't perform next action on a link which was available 10 seconds earlier.

Can anyone suggest how to avoid this wait which is inside webdriver's get function so that after calling get() methods I can add my explicit wait until the element appears (which generally appears in 1-2 seconds) and can move to next steps since I don't bother about the ready state of my current page.

1
  • May be there could be some ugly solution like 1 - before you load the page you override the timeout for loading the page setting it to some rather small value. 2 - you wrap the getUrl with tryCatch where you ignore the exception, 3 - you try to access element on the page after excveption is thrown, 4 - you restore the original value of timeout. However this is just a guess, not sure this will work.
    – Alexey R.
    Commented Jan 4, 2018 at 12:15

3 Answers 3

1

For get() function the sequence will complete first action(open webpage) and wait till page is ready and if the next action is ready, for example element is present and no use for explicit wait or sleep , it will go for it directly and so on

Try : driver.navigate().gotourl("URL") , also it allow some features like forward, back

3
  • fine, but I don't want it to wait until the page is ready because page becomes ready too late and the element on which I want to perform the action is already there. Commented Jan 4, 2018 at 9:22
  • trythis: driver.navigate().GoToUrl("URL") instead of get() because get() wait for your page to load Commented Jan 4, 2018 at 9:49
  • It will not always work, because many times page loads because of clicking on some link. Commented Feb 12, 2018 at 5:56
1

Try setting the PageLoadStrategy capability to none when you create your driver instance, I use this when using Chrome to get around the issue where it times out after 30 seconds. Sometimes the page has not completely loaded but elements are there etc but the page is not in a ready state so it just sits there and does nothing.

0

You can try simulating the browser stop action that a User would do when the page keeps loading.I use this for one of my test scenarios. Try:

   JavascriptExecutor js = (JavascriptExecutor) driver;<br/>
   js.executeScript("return window.stop");

Also you can refer to the below threads:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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