how to verify popup message in selenium


how to verify alert and  popup message in selenium


package automationtesting;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class AlertandPopup {

       public static void main(String[] args) throws InterruptedException {
              // TODO Auto-generated method stub
             
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver driver= new ChromeDriver();
              driver.manage().window().maximize();
              driver.get("https://www.seleniumeasy.com/test/javascript-alert-box-demo.html");
       driver.findElement(By.xpath("//*[@id=\"easycont\"]/div/div[2]/div[3]/div[2]/button")).click();
                 
       Alert alrt = driver.switchTo().alert();
           Thread.sleep(5000);
       String  gtxt =driver.switchTo().alert().getText();
   
           if (gtxt.equals("Please enter your name")) {
            System.out.println(gtxt);
           }
            else {
               System.out.println("false");
            }
           driver.switchTo().alert().sendKeys("Text");
    driver.switchTo().alert().dismiss();
           Thread.sleep(5000);
    driver.quit();
}

}

Post a Comment

0 Comments