try:
if browser.find_element_by_xpath('//[@id="s"]/a').is_displayed():
browser.find_element_by_xpath('//*[@id="s"]/a').click()
browser.switch_to.default_content()
browser.find_element_by_id('btn').click()
except Exception as e:
browser.find_element_by_id('btn').click()
The above code is to close a popup that is displayed on the page when I visit the first time. For the second iteration there is no popup.
I am using try
and except
statements to check for the popup close button and if close button present then close the popup and move forward with other actions, like - click a different button on the default page.
The except
statement displays a Broad Exception
warning in Pycharm IDE
.
Do I use try except
or do I just ignore the warning?
I've tried using if else
instead of try
and except
, but it doesn't work.
At this point I am not planning to capture any exceptions on the website.