1

I'm using selenium chromedriver in nodejs to write some end-to-end tests.

When loading "myurl", the command await driver.get("myurl") always timeouts. In network I see that there is a websocket (appcues) which continues (status "pending").

I assume that selenium thinks there is still things to load, but the page is already loaded, it takes 2 seconds to load the whole page, except that the websocket is still running.

Is there a way to use driver.get() and specify to ignore explicit requests to be finished ? (since the websocket will never stop).

  • may you can try once pageloadtime out with few seconds and handling exceptions if throws..https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#pageLoadTimeout-long-java.util.concurrent.TimeUnit- – murali selenium Aug 26 '19 at 13:56
  • The thing is that I would like to avoid having to catch the exception. Yes I think it could work, but I would be afraid that it's the "best" solution ... – Pierre Emmanuel Lallemant Aug 26 '19 at 14:05
  • I tried. It doesn't work. Once it has reached the timeout, any other call to `driver.*` will throw the same exception "TimeoutError: timeout". – Pierre Emmanuel Lallemant Aug 26 '19 at 14:09
  • 1
    You can try setting capability 'pageLoadStrategy' to 'eager' (Supported in Chromedriver 77 https://chromedriver.storage.googleapis.com/77.0.3865.40/notes.txt) https://www.w3.org/TR/webdriver/#dfn-table-of-page-load-strategies – Rahul L Aug 29 '19 at 11:07
  • 1
    Thanks a lot @RahulL . I set pageLoadStrategy to `none` since chromedriver 77 isn't released yet on npm, and it worked :) You can write an answer and I will validate it. This seems to be an important thing to know about selenium, in order to test pages with websockets. – Pierre Emmanuel Lallemant Aug 29 '19 at 12:16

1 Answers1

1

You can use the pageLoadStrategy capability Documentation WeDriver-W3C

"none" - none causes command to return immediately

"eager" - eager causes command to return after the DOMContentLoaded event fires.

"normal" - The normal state causes command to return after the load event fires on the new page

 let driver = await new webdriver.Builder()
.withCapabilities({ 'pageLoadStrategy': 'none' }) 
.forBrowser('chrome') 
.build()

Note : eager is supported in Chromedriver 77

Rahul L
  • 4,249
  • 15
  • 18
  • 1
    You can add this too : `let driver = await new webdriver.Builder() .withCapabilities({ 'pageLoadStrategy': 'none' }) .forBrowser('chrome') .build()` as an example for nodejs ;) – Pierre Emmanuel Lallemant Aug 29 '19 at 12:33