driver = webdriver.Firefox() #opens firefox
driver.get("https://www.google.com/") #loads google
If it takes too long to load google, how do I make it close the browser and start the code from the beginning?
Set page load timeout via set_page_load_timeout()
and catch TimeoutException
:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
driver = webdriver.Firefox()
driver.set_page_load_timeout(10)
while True:
try:
driver.get("https://www.google.com/")
except TimeoutException:
print "Timeout, retrying..."
continue
else:
break
See also: How to set Selenium Python WebDriver default timeout?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With