Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Handling Popups or Alerts In Selenium Webdriver

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 765
    Comment on it

    Alerts are notification message box, which appeared on screen display. Alerts give some information or ask for permission to perform certain action or job.

    To automate the alert popups has always been a challenging or tricky task for automation tester. 

    There are two types of alert pop-ups :

    • Web based alert pop ups
    • Window based alert pop-ups

    To handle web based alert pop up, Alert interface provides following methods:

    // Get a handle to the open alert, prompt or confirmation
    Alert alert = driver.switchTo().alert();

    //To Click on OK button.


    // To click on Cancel button.


    //To get or captured the text on the Alert.


    //To send the text to the prompt popup


    //Is used to Authenticate by entering the credentials
    alert.authenticateUsing(Credentials credentials);


    1. Launch the URL

    2. Now find the Xpath of alert button 


    import org.openqa.selenium.Alert;
    import org.openqa.selenium.NoAlertPresentException;
    import org.openqa.selenium.WebDriver;  
    import org.openqa.selenium.firefox.FirefoxDriver;  
    import org.openqa.selenium.By;  
    public class AlertHandling {    
            public static void main(String[] args) throws NoAlertPresentException, InterruptedException {         
                WebDriver driver = new FirefoxDriver();   
                // Alert Message handling
                    // Switching to Alert        
                Alert alertbox=driver.switchTo().alert();
                // Capturing alert message.    
                String alerttext=driver.switchTo().alert().getText();  
                // Displaying alert message  
                // Accepting alert  


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: