1

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?

8
  • Have you tried Robot Method ? Commented May 13, 2016 at 9:11
  • Selenium supports file upload, there's no need to use AutoIt. Commented May 13, 2016 at 9:18
  • @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. Commented May 13, 2016 at 10:16
  • @KishanPatel What is the Robot Method? Sorry I am a little new to python. Commented May 13, 2016 at 10:16
  • 1
    @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. Commented May 13, 2016 at 10:30

1 Answer 1

2

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.