Python Selenium Timeout Exception Catch
Almost of your code is working fine except the Driver.Close()
. It should be Driver.close()
. The TimeoutException
will be thrown when the page is not loaded within specific time. See my code below:
from selenium import webdriverfrom selenium.common.exceptions import TimeoutExceptionDriver = webdriver.Firefox()try: Driver.set_page_load_timeout(1) Driver.get("http://www.engadget.com")except TimeoutException as ex: isrunning = 0 print("Exception has been thrown. " + str(ex)) Driver.close()