Python Selenium WebDriver how to add timeout to get(url) function Python Selenium WebDriver how to add timeout to get(url) function selenium selenium

Python Selenium WebDriver how to add timeout to get(url) function


For all the web cretents out there what I used to solve this problem was this. Selenium uses the socket library so I set a timeout on the socket module, this throws an error which we can use to send the escape key to the browser (which stops the page loading):

socket.setdefaulttimeout(2)try:     driver.get(pageLink)except socket.timeout:     #send ESCAPE key to browser


Found this in the docs

selenium.webdriver.remote.webdriver.set_script_timeout(time_to_wait)

Set the amount of time that the script should wait before throwing an error.time_to_wait: The amount of time to waitUsage:driver.set_script_timeout(30)