Create Automation SCRIPT for Alert,Prompt and Confirm

0

Create Automation SCRIPT for Alert, Prompt and Confirm:-

package scs;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Dialogboxexample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
WebDriver driver =new ChromeDriver();
driver.get("https://shivaconceptsolution.com/test3.html");
WebElement btn1 = driver.findElement(By.xpath("//html/body/input[1]"));
btn1.click();
String content = driver.switchTo().alert().getText();
System.out.println("Content of alert is "+content);
driver.switchTo().alert().accept();
WebElement btn2 = driver.findElement(By.xpath("//html/body/input[2]"));
btn2.click();
String content1 = driver.switchTo().alert().getText();
System.out.println("Content of confirm box  is "+content1);
driver.switchTo().alert().dismiss();
WebElement btn3 = driver.findElement(By.xpath("//html/body/input[3]"));
btn3.click();
driver.switchTo().alert().sendKeys("hello");
String content2 = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
System.out.println("Content of prompt box  is "+content2);
}
}
package basicexample;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class PromptConfirm {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  driver.get("file:///D:/alertexample.html");
  driver.findElement(By.cssSelector("input[value=PROMPT]")).click();
  //driver.switchTo().alert().sendKeys("hello");
  String data1=  driver.switchTo().alert().getText();
  System.out.print(data1);
  driver.switchTo().alert().accept();
  driver.findElement(By.cssSelector("input[value=Confirm]")).click();
  //driver.switchTo().alert().sendKeys("hello");
  String data2=  driver.switchTo().alert().getText();
  System.out.print(data2);
  driver.switchTo().alert().accept();
}
}

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)