How to handle alert window?

 package wdProgram;


import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class HandleAlertWindow {


public static void main(String[] args) {


System.setProperty("webdriver.chrome.driver",

"D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("http://localhost/uth/gadgetsgallery/catalog");


driver.findElement(By.linkText("create an account")).click();

driver.findElement(By.id("tdb1")).click();

String alertText = driver.switchTo().alert().getText();

System.out.println(alertText);

driver.switchTo().alert().accept();  //Clicks on OK button

//driver.switchTo().alert().dismiss();  //Clicks on CANCEL button

driver.findElement(By.name("firstname")).sendKeys("Tanmay");

}


}

Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?