{"action":"created","issue":{"url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/1373","repository_url":"https://api.github.com/repos/SeleniumHQ/selenium","labels_url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/1373/labels{/name}","comments_url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/1373/comments","events_url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/1373/events","html_url":"https://github.com/SeleniumHQ/selenium/issues/1373","id":121908594,"number":1373,"title":"HtmlUnitDriver alert handling doesn't handle confirms or prompts","user":{"login":"barrypitman","id":728034,"avatar_url":"https://avatars.githubusercontent.com/u/728034?v=3","gravatar_id":"","url":"https://api.github.com/users/barrypitman","html_url":"https://github.com/barrypitman","followers_url":"https://api.github.com/users/barrypitman/followers","following_url":"https://api.github.com/users/barrypitman/following{/other_user}","gists_url":"https://api.github.com/users/barrypitman/gists{/gist_id}","starred_url":"https://api.github.com/users/barrypitman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barrypitman/subscriptions","organizations_url":"https://api.github.com/users/barrypitman/orgs","repos_url":"https://api.github.com/users/barrypitman/repos","events_url":"https://api.github.com/users/barrypitman/events{/privacy}","received_events_url":"https://api.github.com/users/barrypitman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SeleniumHQ/selenium/labels/D-htmlunit","name":"D-htmlunit","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-13T09:01:00Z","updated_at":"2016-03-22T09:38:42Z","closed_at":null,"body":"The new alert handling functionality in HtmlUnitDriver (`driver.switchTo().alert()`) only handles alert boxes, not other modal dialogs such as confirm and prompt. Other drivers handle confirm, alert and prompt. The test case below illustrates this. \r\n\r\nI know that I can install a confirmHandler for the HtmlUnit WebClient, but that requires modifying the underlying driver and messages are difficult to retrieve. \r\n\r\n```\r\nimport org.junit.Test;\r\nimport org.openqa.selenium.*;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.openqa.selenium.firefox.FirefoxDriver;\r\nimport org.openqa.selenium.htmlunit.HtmlUnitDriver;\r\n\r\nimport static org.hamcrest.CoreMatchers.equalTo;\r\nimport static org.junit.Assert.assertThat;\r\n\r\n/**\r\n * Handling of javascript popups is implemented inconsistently for HtmlUnitDriver, since v2.47.0\r\n *\r\n * @author barry\r\n * @since 2015/12/13\r\n */\r\npublic class AlertTest {\r\n\r\n    @Test\r\n    public void testAlerts() throws Exception {\r\n        testAlertsWithDriver(new ChromeDriver());\r\n        testAlertsWithDriver(new FirefoxDriver());\r\n        testAlertsWithDriver(new HtmlUnitDriver(true)); // test fails for HtmlUnitDriver\r\n    }\r\n\r\n    private void testAlertsWithDriver(WebDriver driver) {\r\n        driver.get(\"https://www.google.com\");\r\n        JavascriptExecutor executor = (JavascriptExecutor) driver;\r\n\r\n        // alerts are implemented\r\n        String alertMessage = \"error!\";\r\n        executor.executeScript(\"alert('\" + alertMessage + \"')\");\r\n        assertThat(driver.switchTo().alert().getText(), equalTo(alertMessage));\r\n        driver.switchTo().alert().accept(); // dismiss the alert\r\n\r\n        // but confirm messages aren't\r\n        String confirmMessage = \"are you sure?\";\r\n        executor.executeScript(\"confirm('\" + confirmMessage + \"')\");\r\n\r\n        // \"NoAlertPresentException: No alert was present\" thrown for HtmlUnitDriver only\r\n        assertThat(driver.switchTo().alert().getText(), equalTo(confirmMessage));\r\n\r\n        driver.switchTo().alert().accept(); // dismiss the confirm\r\n\r\n        driver.quit();\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/comments/199718181","html_url":"https://github.com/SeleniumHQ/selenium/issues/1373#issuecomment-199718181","issue_url":"https://api.github.com/repos/SeleniumHQ/selenium/issues/1373","id":199718181,"user":{"login":"tloist","id":8626748,"avatar_url":"https://avatars.githubusercontent.com/u/8626748?v=3","gravatar_id":"","url":"https://api.github.com/users/tloist","html_url":"https://github.com/tloist","followers_url":"https://api.github.com/users/tloist/followers","following_url":"https://api.github.com/users/tloist/following{/other_user}","gists_url":"https://api.github.com/users/tloist/gists{/gist_id}","starred_url":"https://api.github.com/users/tloist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tloist/subscriptions","organizations_url":"https://api.github.com/users/tloist/orgs","repos_url":"https://api.github.com/users/tloist/repos","events_url":"https://api.github.com/users/tloist/events{/privacy}","received_events_url":"https://api.github.com/users/tloist/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T09:38:42Z","updated_at":"2016-03-22T09:38:42Z","body":"I can confirm this, running with `selenium-java 2.53.0`, `htmlunit 2.20` and `selenium-htmlunit-driver 2.52.0` however downgrading `selenium-htmlunit-driver` to `2.46.0` did not work for me.\r\n\r\nMy test run does something along these lines:\r\n```\r\ndeletionButton.click();\r\nwait.until(ExpectedConditions.alertIsPresent()).accept();\r\n```\r\nwhich works fine for Firefox, but not for HtmlUnit, where it gives me the following error:\r\n```\r\nom.gargoylesoftware.htmlunit.javascript.host.Window confirm\r\nWARNUNG: window.confirm(\"Are you sure you want to delete this entry?\r\n\") no confirm handler installed, simulating the OK button\r\n\r\norg.openqa.selenium.TimeoutException: Timed out after 2 seconds waiting for alert to be present\r\n```\r\n\r\nwhich seems logically, assuming that it auto closes the alert (see log \"simulating the OK button\") and then waits for the alert it just auto-closed unsuccessfully."}}