I'm a first time learner of Selenium with Python and I'm facing the below issue: When I click on a Download template
link in an application, the OS give the User with the options Open
or Save
or Save as
.
It looks like the Selenium webdriver with Python can not support the OS level popup window and we need to use AutoIT or Robot.
The user Minion4 has suggested to use Robot. The comments are below:
The Robot class(java.awt package) should work. Please go through this blog for a better understanding http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/
In this link the Java code is provided. I'm not very clear on how to use this Java code in my Selenium webdriver python script provided below.
Could you please help me how do I use the Robot Java code to be called from the Selenium webdriver Python script in order to Open
or Save
or Save as
the excel file in to any desired location.
Appreciate your help.
Below is the code which work till clicking on the Download Template
link
import time
from selenium import webdriver
from webbrowser import Chrome
import profile
driver = webdriver.Ie('C:/Selenium/IEDriverServer') # Optional argument, if not specified will search path.
driver.get('http://vmslccb05:8082/');
time.sleep(5) # Let the user actually see something!
link = driver.find_element_by_link_text('Download Template')
link.click()
time.sleep(5)
-
1You can't use a Java class in a Python project. Find an alternative that suits your stack like PyRobotkirbycope– kirbycope2015年11月30日 20:40:40 +00:00Commented Nov 30, 2015 at 20:40
-
Take a look at this one stackoverflow.com/questions/860013/…demouser123– demouser1232015年12月01日 12:55:55 +00:00Commented Dec 1, 2015 at 12:55
-
Alternative, you can set a desired download location using Downloading a file at a specified location through python and selenium using Chrome driverGaurav– Gaurav2017年11月27日 14:06:44 +00:00Commented Nov 27, 2017 at 14:06
1 Answer 1
Selenium uses JavaScript which has a security feature called the Same Origin Policy. This policy stops a JavaScript script running in one web domain from stepping outside that domain. This prevents the script you load from a website from jumping to your OS or another website and doing malicious things.
Any automation tool that works at the desktop level will sidestep this. If for example you replace Selenium with TestComplete from Smartbear and use their desktop version, the problem goes away. The downside is that TestComplete is not free.
Another option is to use Sikuli, a java-based image-recognition record & playback tool. You can have it running in the background and have it watch for the Save, Open and Save As buttons. When Sikuli sees one of these buttons, it can interact with them and perform the save. Sikuli is free, but it's screen-resolution dependent.
A third option is to have one of your developers write something for you that bridges the gap.