I was coding a script written in Py and Selenium that slides some slide and clicks a button of each slide, but sometimes, when the button is clicked, a popup is displayed, and other times the script should go regularly.
Can anybody explain me how to handle the ‘exception’ and How can write correctly the Code?
I'm sure to use Try and Exception, but I don't know how to recognize the Popup, so every attempt I tried failed.
try:
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “x”)))
element.click() #Click Slider Button
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “y”)))
element.click() #Click arrow to go to next slide
exception that, if popup is displayed, do this code
except driver.find_element_by_class_name(“z”).is_displayed():
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “f”)))#click to close popup
element.click()
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “y”)))
element.click() #click arrow to go to next slide