import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class PopupsHandling { WebDriver driver=new FirefoxDriver(); @Test public void ExampleForAlert() throws InterruptedException { driver.manage().window().maximize(); driver.get("file:///C:/path/alerts.html"); Thread.sleep(2000); driver.findElement(By.xpath("//button[@onclick='alertFunction()']")).click(); Alert alert=driver.switchTo().alert(); System.out.println(alert.getText()); alert.accept(); } }
Friday, July 3, 2015
PopupsHandling In Selenium
import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class PopupsHandling { WebDriver driver=new FirefoxDriver(); @Test public void ExampleForAlert() throws InterruptedException { driver.manage().window().maximize(); driver.get("file:///C:/path/alerts.html"); Thread.sleep(2000); driver.findElement(By.xpath("//button[@onclick='alertFunction()']")).click(); Alert alert=driver.switchTo().alert(); System.out.println(alert.getText()); alert.accept(); } }
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment