0

I am using selenium to find a page and perform some action.

I have coded it in a way that if chrome is not able to find the page, go to the next one.

I have used try-catch for it but it is failing sometimes.

driver.get(url.text())
try:
    element_present = EC.presence_of_element_located((By.TAG_NAME,'nav'))
    WebDriverWait(driver, 50).until(element_present)

except:
    driver.close()
    continue

Sometimes it runs perfectly but sometimes it throws timeout exception... IDK why? It should go to exception...

File "index.py", line 124, in requests
driver.get(url.text())
selenium.common.exceptions.TimeoutException: Message: timeout

Any insights?

1
  • you are waiting for 50 seconds. You're saying that sometimes it reaches the 50 seconds and timeouts? when you open that page by hand, is it fast? Commented Oct 10, 2019 at 13:10

2 Answers 2

2

The error is in line

driver.get(url.text())

which is not in try-except. Include this line in the try-except block.

Sign up to request clarification or add additional context in comments.

Comments

1

driver.get(url.text()) is not inside the try except block, so the exception won't be caught. The driver took too much time to load, so you received TimeoutException on the get() command. You can set it using

driver.set_page_load_timeout(10)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.