Handle Popup in Selenium

Price: INR 1,299.00
Was: INR 1,799.00

Let’s see, How can you Handle Popup in Selenium. There are two types of Popups-

  • Web base Popup

  • Window base Popup

 

We can’t handle the window base popups using selenium. It’s beyond the selenium capability but we can handle the Web base popups using selenium.

Web base Popups are called Alerts. We can handle the alerts directly using selenium switching functionality.

 

Handle Popup in Selenium

WebDriver offers Alert interface to manage these alert popups. This Alert interface has 4 methods. Which we can use to manage the Alert Popups in our automation testing process.

 

Handle Alert in Selenium

We can handle Javascript alerts in selenium using these methods.

1. Dismiss() – This method is used to dismiss the alert i.e this method click on the ‘Cancel’ button on the alert.

Example —

Alert alert = driver.switchTo().alert();

alert.dismiss();

 

2. Accept() –  This method is used to accept the alert i.e this method click on the ‘Accept’ button on the alert.

Example —

Alert alert = driver.switchTo().alert();

alert.accept();

 

3. getText() –  This method is used to extract the Text from the alert.

Example —

Alert alert = driver.switchTo().alert();

alert.getText();

 

4. sendKeys() –  This method is used to pass the text to prompt alert.

Example —

Alert alert = driver.switchTo().alert();

alert.sendKeys();

 

So here, We have seen how we can manage the Popups in Selenium. It’s very easy to handle the alerts or popups in selenium.

0 Comment

Leave a Reply