Generally Browser popups will open based on the internal application behavior.By using Selenium webdriver we can handle

How to handling a alert,prompt and confirmation:
Alert alertPopup = driver.switchTo().alert();

How to click OK button in alert/confirmation popup/prompt:
alertPopup.accept();

How to click Cancel button in alert/confirmation popup/prompt:
alertPopup.dismiss();

How to get the text which is present on the alert popup/prompt:
alertPopup.getText();

How to enter some text into the alert popup/prompt:
alertPopup.sendKeys("Enter some Text Value");

Complete Code:

Alert alertPopup = driver.switchTo().alert();
//Click OK button in alert/confirmation popup/prompt:
alertPopup.accept();
//Click Cancel button in alert/confirmation popup/prompt:
alertPopup.dismiss();
//Get the text which is present on the alert popup/prompt:
alertPopup.getText();
//Enter some text into the alert popup/prompt:
alertPopup.sendKeys("Enter some Text Value");
Categories: