Chandral
Chandral

Reputation: 448

How do I handle the system windows with Python on Windows OS?

With Selenium Webdriver, I have to upload some files on a website but since the pop-up window for browsing the file location is handled by the operating system and not the browser, I cannot automate that part with Selenium.

So I want to know which framework or module I need to use to work with system windows of Windows OS. Can tkInter or wxPython be used for this?

My script will be used on Windows 7, 8 & 10.

Upvotes: 0

Views: 371

Answers (2)

Andersson
Andersson

Reputation: 52665

Actually, you can upload files without interacting with upload prompt pop-ups.

To be able to handle file upload with selenium you should send path to file to appropriate input field without clicking on "Upload" button. Try following:

path_to_file = 'C:\\Files\\path\\to\\file'  # use your specific path instead
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_to_file)

P.S. Let me know if this code doesn't work as you expect

Upvotes: 1

Petr Blahos
Petr Blahos

Reputation: 2433

You can call autoit3 framework from Python even to open the File Open dialog and fill in the values and press OK or do whatever with the windows. Autoit3 has a dll that can be loaded and called using ctypes. That's what I did in one or 2 projects.

If I understand your question correctly, wxpython or tk won't help you. They can be used to make the windowed UI, not to control other programs.

Upvotes: 0

Related Questions