0

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.

Prophet
  • 32,350
  • 22
  • 54
  • 79
Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36

2 Answers2

0

As per official Selenium documentation

The page load strategy queries the document.readyState

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

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

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')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352