Reputation: 73
I need a solution to download a PDF file from an web application in IE11 using selenium webdriver. Please find the below pop-up which I am trying to handle.
Below are the ways I tried handle the IE popup but unfortunately nothing helped.
I tried to handle this scenario using AutoIT using the below AutoIT script.
Sleep(5000)
Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
If WinExists($hIE,"") Then
WinActivate($hIE,"")
ControlSend($hIE ,"",$hCtrl,"{F6}")
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{TAB}")
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{enter}")
EndIf
Sleep(25000)
Though the above AutoIT script worked, but after execution of AutoIT script the webdriver scripts hangs up. Even a common system.out.println statement is not getting executed after handling the pop-up using above AutoIT script.
I tried to handle this pop-up using Robot class, but hard luck, that also not seems to be working.
I tried to disable this IE pop-up by doing some registry settings by going to the below path, HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\AttachmentExecute\
After doing certain registry settings, this pop-up is successfully getting disabled for .xlsx or .RDP files and not for .PDF files. But In my case I have a test case where I need to download a .pdf file and proceed with further webdriver scripts.
Guys, suggestion of any other workaround will be greatly appreciated.
Thank you, Sudheendran P L
Upvotes: 2
Views: 7278
Reputation: 99
I had the same problem. Click button does not work properly in this case with IE. I switched clicking button for focusing it with sendKeys()
and then pressing with Enter.
Try this:
Robot robot;
try {
// pressing download button
button.sendKeys("""");
robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
// handling download
webDriver.wait(2000);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
webDriver.wait(200);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
} catch (Exception e) {
e.printStackTrace();
}
You can use Thread.sleep()
instead of driver.wait()
and should work as well.
Upvotes: 0