-1

In my case, I don't want to wait more than 15 seconds after calling the method driver.get(). I have the following code:

...
driver.set_page_load_timeout(15)
try:
    driver.get(url) 
except TimeoutException as e:
    pass

try:
    WebDriverWait(driver, 0.5).until(EC.alert_is_present())
    alert = input_driver.switch_to.alert
    alert.dismiss()
except (TimeoutException, WebDriverException):
    pass

But it still takes in some cases (not sure when) more than 5 minutes. What am I doing false?

  • Does this answer your question? [Selenium + Python: How to stop page loading when certain element gets loaded?](https://stackoverflow.com/questions/44503576/selenium-python-how-to-stop-page-loading-when-certain-element-gets-loaded) – Prophet May 27 '21 at 14:54
  • Yeah... so change the time to 15 seconds!! – C. Peck May 27 '21 at 16:30

1 Answers1

1

The page keeps loading for some time, you probably want to set the pageLoadStrategy capability to none and then stop the loading when the element you need is there, see this answer for a more detailed explanation.

  • 1
    Change the value to 15 and the condition to wait until to the one that fits your needs and you're good! – Álvaro Zamora May 27 '21 at 15:05
  • After the website has loaded whatever you need from it, that script will stop it from loading anything else you don't need. – Álvaro Zamora May 27 '21 at 15:13
  • If the page times out it will go to the catch block in your code and you can handle that there. The window close code only stops the page from loading further from what you need, you don't have to include it if you don't want to. – Álvaro Zamora May 28 '21 at 09:34