Java - Selenium WebDriver - How do I check if the

2019-06-12 02:21发布

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?

File Download Dialog Box

1条回答
相关推荐>>
2楼-- · 2019-06-12 02:27
  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.
        }
查看更多
登录 后发表回答