Created
February 4, 2015 17:43
-
-
Save udayanem/8b4672c13845b523af3b to your computer and use it in GitHub Desktop.
How to handle JavaScript alerts or dialog boxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.*; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
public class JavaScriptPopups | |
{ | |
public static void main(String[] args) | |
{ | |
WebDriver driver=new FirefoxDriver(); | |
//Demonstration of Alert Box | |
driver.get("file:///E:/Programming%20Samples/HTML%20Samples/AlertBoxEx.html"); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
driver.findElement(By.name("clickMe")).click(); | |
Alert alert=driver.switchTo().alert(); | |
System.out.println(alert.getText()); | |
alert.accept(); | |
driver.close(); | |
//Demonstration of Conformation Box | |
driver.get("file:///E:/Programming%20Samples/HTML%20Samples/ConformationBoxEx.html"); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
driver.findElement(By.name("clickMe")).click(); | |
Alert alert=driver.switchTo().alert(); | |
System.out.println(alert.getText()); | |
// alert.accept(); | |
alert.dismiss(); | |
// driver.close(); | |
//Demonstration of Popup | |
driver.get("file:///E:/Programming%20Samples/HTML%20Samples/PopUpEx.html"); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
driver.findElement(By.name("clickMe")).click(); | |
Alert alert=driver.switchTo().alert(); | |
System.out.println(alert.getText()); | |
alert.sendKeys("Uday"); | |
// alert.accept(); | |
alert.dismiss(); | |
// driver.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment