How to upload images using Selenium webdriver with ruby

There are different ways to handle file uploads with Selenium Webdriver.

In Ruby, the image cannot be uploaded directly from the system local path. So this can be achieved using AutoIt software.

Following are the steps to achieve this.
1. First you need to install AutoIt and sciTE4AutoIt3

It has a customized Lexer for AutoIt3 which handles the Syntax Highlighting.

2. Open the sciTEScript Editor and copy the following code.

WinWaitActive("File Upload") 
Send("D:\images\m.jpg")     //Select image path.
ControlClick("","Open", "Button1")

Save it as “Test.au3” and run the code using ‘F7’ key or Click on tools and select the build option. After running the script, it will automatically create the “.exe” file in same folder.

For example, if the name of the file is Test.au3, the .exe will be generated with the same name but with .exe extension say “Test.exe”.

3. The generated .exe needs to be called in the automation script (Ruby) where the image needs to be uploaded.

Syntax:

f = IO.popen("D:/a/web/U/test.exe")
puts f.readlines