Skip to content Skip to sidebar Skip to footer

Download Files Automatically In Internet Explorer 11 With Python And Selenium

I am trying to download some Excels files throught multiple Internet Explorer 11 windows at the same time by using Python and Selenium. The problem appens when the 'Save As' Pop Up

Solution 1:

Tried in Java, file was dowloaded.

driver.findElement(By.xpath("//body")).sendKeys(Keys.chord(Keys.CONTROL, "j"));
Thread.sleep(2000);
Robotrb=newRobot();
rb.keyPress(KeyEvent.VK_ENTER);

Explaination:

  1. First click on the button / link to download the file.this pop up will be seen enter image description here
  2. Click "Ctrl+j" this will open the "View Downloads pop up". then click enter , since the focus will be on the recent file, it will be downloaded

Solution 2:

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

By using this program, first, we could get the hyperlink href attribute value, and then, execute the Command Prompt Command to download the file from the link.

Sample code:

import time
import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreZoomSetting'] = True
driver = webdriver.Ie("D:\\Downloads\\webdriver\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe",capabilities= cap)


driver.get("<website url>")

time.sleep(3)

btn = driver.find_element_by_id("btnDowloadReport")


hrefurl = btn.get_attribute("href")

os.system('cmd /c D:\\temp\\wget.exe -P D:\\temp --no-check-certificate ' + hrefurl)


print("*******************")

Html resource:

<a id="btnDowloadReport" href="https://github.com//sakinala/AutomationTesting/raw/master/samplefile.pdf" >Download</a>

[Note]: please remember to change to webdriver path and website url to your owns.

More detail information about using wget, you could refer to this article.

Post a Comment for "Download Files Automatically In Internet Explorer 11 With Python And Selenium"