seleniummodal-dialogwebdriverdia

How to click on check box inside confirm box in selenium webdriver in java


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


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.