Question

i have one modal dialog. I wanted to click on check box. How to do that using selenium webdriver in java

here is the link http://sislands.com/coin70/week1/dialogbox.htm

u can click there and will get checkbox

Was it helpful?

Solution

You can't do that using selenium, but you can using java robot. Here is the code which will check the checkbox on the dialog on FireFox 28:

WebDriver driver = new FirefoxDriver();
driver.get("http://sislands.com/coin70/week1/dialogbox.htm");
driver.findElement(By.xpath("//input[@value='confirm']")).click();
Alert alertDialog = driver.switchTo().alert();
alertDialog.dismiss();
Robot robot = new Robot();
robot.delay(5000);
for (int i = 0; i <= 6; i++) {
    robot.keyPress(KeyEvent.VK_TAB);
}
robot.keyPress(KeyEvent.VK_SPACE);

This is not good approach to do like this, but it works. Checked it by myself. Also checked the same approach on chrome, it won't work with chrome.

OTHER TIPS

Assuming you are meaning the checkbox that comes up when more than one modal dialog is popped up from the browser, more specifically:

"Check this box to not allow any more popups from this page"

Then No.. This is a security feature designed in the browser. The Webpage does not put that checkbox in there. If you want to avoid it, investigate turning off security for Chrome or whatever browser you are using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top