2

If the page we are interacting with responds slowly, what is the best way to handle this situation when developing test scripts? I'm kinda confused right now:

a) Use WebdriverWait and specify the condition that we expect it to meet before continuing.

b) Use the sleep delays provided by the language we are using to temporarily pause the execution of the test and wait for the page to finish loading.

c) Write an infinite loop that checks the status of the page and exits when the expected condition is met.

d )Do nothing and allow the test to continue running without interruption.

Which one would be the best way to go and why? Can give me an example?

ybressler_simon
  • 494
  • 1
  • 10

2 Answers2

2

Of course WebdriverWait would be the way forward in the case where the page you are interacting with responds slowly.

You can find a couple of relevant detailed discussions in:

ybressler_simon
  • 494
  • 1
  • 10
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
2

The best practice is definitely (1) to use WebdriverWait and specify the condition that we expect it to meet before continuing.
2) Using hardcoded delays will significantly increase the test running time while it still will not be reliable enough since sometimes web page loading will take more time due to server load / slow internet connection etc. While setting hardcoded pauses to extremely long to make sure they will be enough in 100% cases will make your test run extremely long.
3) Selenium WebdriverWait are already ready to use, good enough loops checking for most useful conditions. Making the loop infinite is strongly not recommended since it may cause your code stuck with infinite loops.
4) "Do nothing and allow the test to continue running without interruption" will probably make you code not really good. Possibly it will make your code not working / failing in case of page loading delays / slow network etc.

Prophet
  • 21,440
  • 13
  • 47
  • 64