Home > Mobile >  Web Driver Wait is not working when page load strategy is set to none
Web Driver Wait is not working when page load strategy is set to none

Time:01-17

Selenium Version: 4.7.2

I only want to wait for specific page to load so I want to disable the default behavior of driver page load strategy.

I disable it with the following code.

options = webdriver.ChromeOptions()
options.page_load_strategy = "none"

Now for the page I want to wait for it to load, I use the following code.

WebDriverWait(web, seconds).until(
    lambda _: web.execute_script("return document.readyState") == "complete"
)    

The problem is that when page_load_strategy is none. The waiting code doesn't work i.e. it doesn't wait for the page readyState to be complete.

CodePudding user response:

As per enter image description here

Seems that when you set driver capabilities / options to ignore web page document.readyState state this surpasses the code you are trying to apply here using the same parameter, the document.readyState

CodePudding user response:

Seems the lambda expression passed to until() is errorprone. You can try the following line of code:

WebDriverWait(driver, 20).until(lambda driver: driver.execute_script('return document.readyState') == 'complete')
  • Related