Jakob
Jakob

Reputation: 268

Selenium: Do not wait even for initial html

I would like to use selenium to test a webpage where the initial html contents builds up in a "streaming" fashion.

As simple example, assume that the webpage html is

<!DOCTYPE html>
<html>
  <head>
    <title>title</title>
  </head>
  <body>
    <p id="p1">foo</p>
    <p id="p2">bar</p>
  </body>
</html>

and that the webserver sends everything up to including #p1 immediately, then waits for 10s, then sends the rest of the page.

I would basically like to open that page in selenium, "manually" wait until the id #p1 exists, check that foo is in the page text (or html) so far but bar is not; wait for 10s and then check that bar is here.

It seems that this is not covered by "Page loading strategy": According to the docs (and to my attempt), even none "waits until the initial page is downloaded".

Question: Is there a "Page loading strategy" that allows me to continue before the html is loaded? Or is there some option for / alternative to the usual navigation command that lets me immediately continue with selenium? (Such as: Instead of navigate to the page, simulate entering the url in the address bar and pressing return, or whatever..)

Upvotes: 1

Views: 46

Answers (1)

Rahul L
Rahul L

Reputation: 4349

As a work around . We can interrupt the loading of page by using page load timeout

Page load timeout - Provides the timeout limit used to interrupt an explicit navigation attempt.

By Default value is set to '300,000' milliseconds

In Java

driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.SECONDS); 
driver.get("url") 

driver.get() - > It will throw timeout exception if page is not loaded in 1 second. You can catch the exception and continue with other operations.

Upvotes: 1

Related Questions