import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class KeyandMouse {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D:\\vishal\\selenium\\chromedriver_win32\\dasdf\\chromedriver.exe");
//path of exe file of chromedriver
WebDriver driver = new ChromeDriver();
//create object of webdriver as a driver name
String url="http://demo.guru99.com/test/delete_customer.php";
driver.get(url);
//you also write direct url in driver.get("https://www.amazon.in/");
driver.findElement(By.xpath("http://demo.guru99.com/test/delete_customer.php")).sendKeys("abcd");
//we find xpath of customer id and pass value
driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/input[1]")).click();
//here we find xpath of submit button and perforn click event
//when you click that time you see alert box we directly not handle that alert box
Alert alert = driver.switchTo().alert();
//here we switch control to alert box
String alertmesage=driver.switchTo().alert().getText();
System.out.println(alertmesage);
//we take alert message and print
//it is not important to perfoem we need just want to see alert message that why we perforn
alert.accept();
//alert.dismiss(); if you want to dismiss the alert then we use this command
}
}
No comments:
Post a Comment