0

I am using selenium webdriver to do some automation on IE11 and am stuck on auto-downloading file while screen is locked.

The file download starts after pressing a button. That button does not link to a url for the download file, but seemed to link to a javascript function. I have managed everything until pressing the button but am stuck on the bottom bar prompt from IE11 (open or save). For security reasons I have to use IE11 and do the automation in locked screen. I have tried to send Alt+S using WScript.Shell, but it only seemed to work after I unlock the screen. Here's what I've tried.

shell = win32.Dispatch("WScript.Shell")

config = Path(localpath + localfile)

#confirm file exists
while not config.is_file():
    shell.SendKeys("%s", 0)
    time.sleep(2)

Is there a way to bypass the IE prompt and automatically save the file to the download folder during locked screen?

DanielG
  • 5
  • 1

1 Answers1

0

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)

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • Thanks! Yet it doesn't work in my situation. I am getting None with getAttribute so it doesn't seem to have a URL. The button for download goes like this. – DanielG May 28 '19 at 05:56
  • Also, if Wget cannot achieve this, is it possible to use something like command shell to directly control IE and click save? – DanielG May 28 '19 at 07:12
  • Please check the Edit, you could try to use the find_element_by_id method to find the element, then using the get_attribute method to get the value. – Zhi Lv May 28 '19 at 09:18
  • In my sample, the Wget works well in my C# application. As far as I know, we cannot control the IE browser download prompt button using script, if you want to use a command script to download file, we can bypass this dialog box using a separate program (without using IE browser). – Zhi Lv May 28 '19 at 09:23
  • it turns out that my get_attribute can only return none in my case... But I've found other solutions for this issue. Thanks! – DanielG May 30 '19 at 06:37