-1

I want to automate testing using selenium webdriver in java. I am automating downloading file section but unable to handle save as dialogue window that pop up while downloading in IE.By clicking link IE shows to save or open file from pop up window. enter image description here

 driver.findElement(By.xpath("//img[@alt='145.36KB File Size']")).click();
DEO KUMAR DAS
  • 99
  • 2
  • 12
  • I think that the dialog might count as a "popup" which means you might have to switch windows and 'handle' the popup since its not part of the actual webpage itself. Anything used to handle popups might be the way to handle this. I don't think you can get to it from xpath. The way to do this easily is outlined here https://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java might be a good thing to try. – Redacted Oct 04 '18 at 11:23

1 Answers1

1

First download autoit: https://www.autoitscript.com/site/autoit/ Add it to path inside windows env variables so it can be executable from command prompt.

Example Path:

C:\Program Files (x86)\AutoIt3

Here is an example method that handles auto it scripts.

public static void saveFileInternetExplorer() throws Exception {

        String pathToAutoItScript = "C:\\save_file_IE11.au3";
        String command = "AutoIt3.exe " + pathToAutoItScript;
        System.out.println("AutoIt command: " + command );
        String output = new CommandLine(command).executeGetOutput();

        if (output.contains("ERROR")) {
            throw new Exception("AutoIt script error: " + output);
        }

        System.out.println(output);
    }

AutoIt script to save file in IE 11

  • save_file_IE11.au3

Sleep(5000)

    Local $hIE = WinGetHandle("[Class:IEFrame]")
    Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")

    If WinExists($hIE,"") Then
        WinActivate($hIE,"")
        ControlSend($hIE ,"",$hCtrl,"{F6}")          ; Gives focus to Open Button
        Sleep(500)
        ControlSend($hIE ,"",$hCtrl,"{TAB}")          ; Gives focus to Save Button
        Sleep(500)
        ControlSend($hIE ,"",$hCtrl,"{enter}")        ; Submit whatever control has focus
    EndIf
Sleep(3000)

After clicking on the download button, run the autoit3 script this should save the file.

Good luck!

Infern0
  • 2,565
  • 1
  • 8
  • 21