Java - Selenium WebDriver - How do I check if the File Download Dialog Box is visible? (Not download Only visibility)

冷暖自知 提交于 2019-12-08 12:22:54

问题


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:


  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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!