Java - Selenium WebDriver - 如何检查文件下载对话框是否可见? (不下载只有可见性) [英] Java - Selenium WebDriver - How do I check if the File Download Dialog Box is visible? (Not download Only visibility)

查看:315
本文介绍了Java - Selenium WebDriver - 如何检查文件下载对话框是否可见? (不下载只有可见性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

任何帮助?

推荐答案


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

这篇关于Java - Selenium WebDriver - 如何检查文件下载对话框是否可见? (不下载只有可见性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆