-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HtmlUnitDriver alert handling doesn't handle confirms or prompts #1373
Comments
I can confirm this, running with My test run does something along these lines:
which works fine for Firefox, but not for HtmlUnit, where it gives me the following error:
which 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. |
I can confirm on v.2.52.0 - HTMLUnit not handling .accept(). Found this issue when researching. Here is my very brute force workaround: public abstract class MyAbstractTest {
protected WebDriver webDriver;
private WebClient webClient;
// ...
@Before
public void setup( )
{
webDriver = new org.openqa.selenium.htmlunit.HtmlUnitDriver(){
@Override
protected WebClient modifyWebClient(WebClient webClient){
org.apache.commons.logging.LogFactory.getFactory( ).setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(java.util.logging.Level.OFF);
AbstractHtmlUnitTest.this.webClient = webClient;
return webClient;
}
};
((org.openqa.selenium.htmlunit.HtmlUnitDriver) webDriver).setJavascriptEnabled(true);
//webDriver = new org.openqa.selenium.firefox.FirefoxDriver( );
}
// ...
protected void clickLinkAndHandleConfirm(By by, final boolean acceptConfirm)
throws IOException {
// Firefox, or other driver
if (webClient == null) {
clickLink(by);
Alert alert = new WebDriverWait(webDriver, DEFAULT_WAIT_SECONDS).until(ExpectedConditions.alertIsPresent());
if (acceptConfirm) {
alert.accept();
} else {
alert.dismiss();
}
}
// HTMLUnit Driver
else {
webClient.setConfirmHandler(new ConfirmHandler() {
@Override
public boolean handleConfirm(Page page, String message) {
return acceptConfirm;
}
});
clickLink(by);
webClient.setConfirmHandler(null);
}
}
// ...
}
`` |
HtmlUnitDriver issues should now be tracked on the separate project: please log a new issue there |
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.I know that I can install a confirmHandler for the HtmlUnit WebClient, but that requires modifying the underlying driver and messages are difficult to retrieve.
The text was updated successfully, but these errors were encountered: