I am trying to download xls file for a website. When I click the link to download the file, I get a javascript confirm box. I handle it like below
ConfirmHan
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setTimeout(2000);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.waitForBackgroundJavaScript(2000);
//get General page
final HtmlPage page = webClient.getPage("http://your");
//get Frame
final HtmlPage frame = ((HtmlPage)
page.getFrameByName("Frame").getEnclosedPage());
webClient.setConfirmHandler(new ConfirmHandler() {
public boolean handleConfirm(Page page, String message) {
return true;
}
});
//get element file
final DomElement file = mainFrame.getElementByName("File");
final InputStream xls = file.click().getWebResponse().getContentAsStream();
assertNotNull(xls);
}