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  as e:
        browser.find_element_by_id('btn').click()

This piece of code is to close a up that is displayed on the page when I visit the first time. For the second iteration there is no up.

I am using the the try and except statements to check for the popup close button and if present close the popup and move forward with other actions which is to click a different button on the default page.

The except statement displays a “ Exception” in Pycharm IDE. Do I use try except or do I just ignore the ?
I tried without the try and except instead used if else which didn’t work.
At this point I am not planning to capture any exceptions on the website.



Source link https://sqa.stackexchange.com/questions/35253/pop-up--in--using-try-and-except--gives-a-broad-exception-w

LEAVE A REPLY

Please enter your comment!
Please enter your name here