Some websites tend to keep loading even after all the elements in the page are loaded. This is usually not a problem for humans but selenium tends to wait until the page fully finishes loading even when it could already interact with the given element. Is there a way to bypass this or maybe stop loading when a certain element is detected? I couldnt figure it out from other posts. Thanks
Asked
Active
Viewed 317 times
0
-
1You mean driver.set_page_load_timeout(5) or etc? Or wait till the webdriver wait picks up the presence of an element then execute a window.stop in a driver.execute(). – Arundeep Chohan Mar 16 '21 at 11:00
-
Wait till element is loaded and then stop loading so the second option. – Mátyás Szabolcs Mar 16 '21 at 21:50
-
https://stackoverflow.com/questions/44503576/selenium-python-how-to-stop-page-loading-when-certain-element-gets-loaded has an example. – Arundeep Chohan Mar 17 '21 at 00:26
1 Answers
0
You need to use a load strategy. Default is normal
, other options are eager
and none
https://www.selenium.dev/documentation/en/webdriver/page_loading_strategy/
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)
# Navigate to url
driver.get("http://www.google.com")
driver.quit()

Tarun Lalwani
- 142,312
- 9
- 204
- 265