shix
shix

Reputation: 11

How to handle selenium exceptions in splinter (python)?

Sometimes, when I try to click a button, it's covered by another element and I get a selenium.common.exceptions.ElementClickInterceptedException. It happens rarely and it's not a huge deal, so I would like to ignore it and keep going instead of exiting the script.

I tried

except selenium.common.exceptions.ElementClickInterceptedException as c:

and

except ElementClickInterceptedException as c:

Both throw errors, I'm assuming, because I'm not importing selenium directly, I'm using splinter: NameError: name 'ElementClickInterceptedException' is not defined

Example of my code:

if browser.is_element_present_by_css('a.User', wait_time=15):
    try:
        browser.find_by_css('a.User').first.click()
    except ElementClickInterceptedException as c:
        pass

How do I handle an error selenium throws while using splinter?

Upvotes: 1

Views: 184

Answers (1)

supputuri
supputuri

Reputation: 14145

Try using javascript to click.

browser.execute_script("arguments[0].click()", browser.find_by_css('a.User').first)

Upvotes: 1

Related Questions