Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python selenium timeout exception does not pass compiling

I have some Selenium WebDRiver code that searches for the "Next" button and if it exists, it clicks it. If not, the script should catch TimeoutException and continue.

Code:

from selenium.common.exceptions import TimeoutException

def clicking_next_page():
    btn_next_to_click=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='next']")))
    try:
        btn_next_to_click.click()
        crawler()
    except TimeoutException:
        pass

Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 90, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:

>Solution :

You didn’t include the line that actually times out in the try-catch. Simply move the WebDriverWait line down inside the try.

def clicking_next_page():
    try:
        btn_next_to_click = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='next']")))
        btn_next_to_click.click()
        crawler()
    except TimeoutException:
        pass
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading