Search code examples
pythonpython-3.xseleniumselenium-chromedriverwebdriverwait

How to use Close a dynamic Popup with python Selenium


Im trying to close this popup but i cant, i have tried using find.element.by.xpath() with all the different possibilities i guess, tried using switch_to _alert().dismiss() but nothing seems to help Any help is much appreciated, Thanks

enter image description here


Solution

  • It seems NOT an Alert. It is just another element on webpage.

    Induce WebDriverWait() and wait for element_to_be_clickable() and following css selector

    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div#dismiss-button"))).click()
    

    You need to import these libraries:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    

    Note: if you get timeout error then please check if the element is under iframe. If so you need to switch to iframe in order to interact the button element.