How to work with Alert using Selenium WebDriver ? - Source Code on June 28, 2020 Get link Facebook Twitter Pinterest Email Other Apps package practice; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class AlertExample { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\drivers\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); // To Start Chrome Browser //To Open URL driver.get("https://www.magneticautomation.in/2019/01/alert-example.html"); //For Clicking driver.findElement(By.xpath("//*[@id=\"post-body-5405753133268992336\"]/div/button[3]")).click(); Alert a = driver.switchTo().alert(); //For focusing on Alert //For printing text of Alert System.out.println(a.getText()); //For typing in Alert's input field a.sendKeys("Google"); //a.accept(); // Pressing OK a.dismiss(); // Pressing on Cancel } } Comments
Comments
Post a Comment