簡體   English   中英

Java-Selenium WebDriver-如何檢查“文件下載”對話框是否可見? (不下載僅能見度)

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

是否可以使用Selenium WebDriver或任何其他Java庫檢查IE中的“文件下載”對話框是否可見?

我不想下載文件。 我無法驗證對話框的可見性。

另外,我無法關閉對話框。

有什么幫助嗎?

文件下載對話框

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM