问题
Is it possible to check whether the File Download Dialog Box in IE is visible using Selenium WebDriver or any other Java Library?
I don't want to download the file. I'm unable to verify the visibility of the dialog box.
Also I'm unable to close the dialog box.
Any help?

回答1:
- Check if your IE UNEXPECTED_ALERT_BEHAVIOR is set to IGNORE
try{
//Click the link that brings up the download dilaog
// Perform your next step : This is where the script will throw the excpetion due to the modal dialog.
}
catch(Exception e){
if(e.getMessage().contains("Modal dialog present")) {
System.out.println("A modal dialog is present. (which can be a download dialog)" );
System.out.println(e.getMessage());
// the exception message includes text contained in the dialaog. You can use it for validaton.
//Use a java robot class to cancel the dialog
Robot robot= new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
//Since the current focus is on cancel.. else use robot.keyPress(KeyEvent.VK_TAB) as needed.
}
来源:https://stackoverflow.com/questions/20540418/java-selenium-webdriver-how-do-i-check-if-the-file-download-dialog-box-is-vi