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

What is data driven testing?

API Automation Testing Script to check Response

How to handle frame window in selenium?

How to work with mouse hover menu in selenium?

How does Selenium Webdriver handle SSL certificate in Chrome?