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?

user2726634
  • 77
  • 2
  • 12
  • Have you tried Robot Method ? – Kishan Patel May 13 '16 at 09:11
  • Selenium supports file upload, there's no need to use AutoIt. – Florent B. May 13 '16 at 09: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. – user2726634 May 13 '16 at 10:16
  • @KishanPatel What is the Robot Method? Sorry I am a little new to python. – user2726634 May 13 '16 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 `` and not the button. It is documented and I've also tested it may times. – Florent B. May 13 '16 at 10:30
  • @FlorentB. Yea I know that input method. But this is a Flash upload. So there is no place to put the location of the file. I just click Upload and the File Upload window opens up. – user2726634 May 13 '16 at 10:37
  • Robot Class is there to upload files. Robot method basically listens to your mouse and keyboard actions so you can easily handles pop-ups which are windows based and not browser based. I don't know about python.Hope this helps you. http://stackoverflow.com/questions/860013/is-there-a-python-equivalent-to-javas-awt-robot-class But you can refer – Kishan Patel May 13 '16 at 10:48
  • @FlorentB, I would try to disable the Flash plugin and see if there is an alternative input tag. The Flash component might also have an upload function to directly upload a file. – Florent B. May 13 '16 at 12:19

1 Answers1

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")
m.elewa
  • 187
  • 1
  • 9