【问题标题】:Java - Selenium WebDriver - How do I check if the File Download Dialog Box is visible? (Not download Only visibility)Java - Selenium WebDriver - 如何检查文件下载对话框是否可见? (不下载仅可见性)
【发布时间】:2013-12-12 10:05:25
【问题描述】:

是否可以使用 Selenium WebDriver 或任何其他 Java 库检查 IE 中的文件下载对话框是否可见?

我不想下载文件。我无法验证对话框的可见性。

我也无法关闭对话框。

有什么帮助吗?

【问题讨论】:

    标签: java selenium internet-explorer-8 webdriver ui-automation


    【解决方案1】:
    1. 检查您的 IE UNEXPECTED_ALERT_BEHAVIOR 是否设置为 IGNORE

    试试{

         //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.
            }
    

    【讨论】:

    • 该对话框不是 JavaScript 警报。
    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2012-06-11
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多