Reputation: 11
driver = webdriver.Chrome()
driver.get(url)
driver.execute_script("window.stop();")
When I try to open a site, the page keeps loading and the code stops at driver.get(url) If I manually stopped the page loading, it completes the code. How to make selenium stop the page loading and move to the next line Wait for your help guys
Upvotes: 1
Views: 2987
Reputation: 8444
"Eager" page loading strategy will make WebDriver wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes (DOMContentLoaded event fire is returned).
Example usage for Python:
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()
Upvotes: 4
Reputation: 9969
You can use page_load time out or using page_load strategy in options.
driver.set_page_load_timeout(10)
try:
driver.get(url)
except:
print('error')
Or using
options.page_load_strategy = 'eager'
Upvotes: 1