Closing a generic pop up in Selenium Closing a generic pop up in Selenium selenium selenium

Closing a generic pop up in Selenium


It works perfectly, give it a try ;)

from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsoptions = Options()options.add_argument("--disable-notifications")browser = webdriver.Chrome('C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe', chrome_options=options)


As I can see, it's not an alert box!!. It is just a Simple Pop-up that appears when you are entering the page and it is present in main window itself(no need of switching and closing it too). Use the below code to close it.

driver.find_element_by_xpath('//div[contains(@class,"ui-dialog") and @aria-describedby="dialogContent2"]//button[@title="Close"]').click()


The popup you are trying to close is not a browser alert but a DOM popup. A browser alert is a dialog box that the browser creates at the OS level. (It is appears as an additional window on your desktop.) You can use .switch_to_alert() to close these alerts. A DOM popup is just an HTML element that happens to be used the the page as if it were a dialog box. This popup has existence only in your browser. (The OS does not know about it.) You cannot use .switch_to_alert() to close DOM popups.

To get this popup and close it, you have to inspect the DOM (like you've started doing), find the DOM element that represents the close button and have Selenium click it.