How to Start Automatic Download of a File in Internet Explorer

How to start automatic download of a file in Internet Explorer?

SourceForge uses an <iframe> element with the src="" attribute pointing to the file to download.

<iframe width="1" height="1" frameborder="0" src="[File location]"></iframe>

(Side effect: no redirect, no JavaScript, original URL remains unchanged.)

How to automatically download file in IE in locked screen

As far as I know, WebDriver has no capability to access the IE Download dialog boxes presented by browsers when you click on a download link or button. But, we can bypass these dialog boxes using a separate program called "wget".

we can use command-line program and this wget to download the file. Code as below (the following code is C# code, you could convert it to Python):

            var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL, // "http://demo.guru99.com/test/yahoo.html";
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};

//IE_DRIVER_PATH: @"D:\Downloads\webdriver\IEDriverServer_x64_3.14.0";
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
Thread.Sleep(5000);

//get the download file link.
String sourceLocation = driver.FindElementById("messenger-download").GetAttribute("href");
Console.WriteLine(sourceLocation);

//using command-line program to execute the script and download file.
String wget_command = @"cmd /c D:\\temp\\wget.exe -P D:\\temp --no-check-certificate " + sourceLocation;

try
{
Process exec = Process.Start("CMD.exe", wget_command);
exec.WaitForExit();
Console.WriteLine("success");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process

More details, you could refer to this article.

Edit: Since you are using python, you could use the find_element_by_id method to find the element, then using the get_attribute method to get the value. More details, you could check these articles:

Get Element Attribute

Python + Selenium for Dummies like Me

WebDriver API

Get value of an input box using Selenium (Python)

How to enable automatic downloads in IE11

I found a way to do this, but you need to use User32.dll sendmessage() function, after you press button\link and you have your download dialog i use sendmessage to send key's i send:

1- (F6) it will select the download dialog.

2-(Tab) -it will select the first option Save.

3- (Enter) will press Save button that will save file to deafault derectory

4- For 100% i check in registry the defeaul folder of IE and easy find my file and copy it to directory that i need.

Why i use sendmessage and not sendKey?

Answer: sendmessage will still press on buttons even if windown is lock no need UI.



Related Topics



Leave a reply



Submit