1
votes

I am using Selenium and AutoIT to upload images to a site. Now I need to choose a file from the "File Upload" Window in Firefox and click Enter. So this is the AutoIT part of the code:

driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div/div/ul[1]/li/button").click()
    autoit.win_wait_active("File Upload", 5)
    autoit.send(os.path.join(mpath,"1.jpg"))
    autoit.send("{ENTER}")

This script works fine Now the problem is the Window needs to be active on my computer in order for the file to be uploaded and so I cannot do any other work while the script is running. How do I send the same data without making the window active?

1
Have you tried Robot Method ?Kishan Patel
Selenium supports file upload, there's no need to use AutoIt.Florent B.
@Florent B. I don't think Selenium supports File Upload through a Window. I mean I cannot select the Firefox Upload window with Selenium as far as I have read the docs.user2726634
@KishanPatel What is the Robot Method? Sorry I am a little new to python.user2726634
@user2726634, yes you can upload a file with Selenium with element.sendKeys("full file path"). Note that the element needs to be the <input> and not the button. It is documented and I've also tested it may times.Florent B.

1 Answers

2
votes

use this instead:

    autoit.win_wait("[CLASS:#32770;TITLE:Open]", 60)
    autoit.control_send("[CLASS:#32770;TITLE:Open]", "Edit1", os.path.join(mpath,"1.jpg"))
    autoit.control_click("[CLASS:#32770;TITLE:Open]", "Button1")