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.

time.sleep(5) # Let the user actually see something!
link = driver.find_element_by_link_text('Download Template')

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.