AutoIT is a powerful tool to use in conjunction with Ruby/Watir because it allows you to manipulate windows and simulate actions without requiring the use of the source code. This is especially useful for pop-ups such as modal dialogs or file downloads.

Let’s say your automated testing requires a file download in Firefox. Using AutoIT you can grab information from a typical download prompt.

# This will ensure that your active window is the download prompt. It is very important to make sure that you are dealing with the correct window when using AutoIT since you will be getting information from the active window or sending key strokes to the active window.

# This will grab the full title of the active window. This is useful when you are dealing with dynamic file names because you can later call back ‘downloadtitle’ if you want to access the file at a later point.

# You can also send simple key strokes such as the ENTER key which would, in this case, initiate the download.


# Using the WinExists function, you can confirm that the download was successfully initiated. An output of 1 would indicate that a window titled “Downloads” does exist. An output of 0 would indicate that it does not exist.

# Note: If you want to get the file name, you will need to manipulate the downloadtitle variable. downloadtitle is currently ‘Opening Lead_1286919229280.csv’. So if you want just the file name, which is ‘Lead_1286919229280.csv’, you will need to use character indices.

# Filename1 is now equal to ‘Lead_1286919229280.csv’

The download prompt is a little different in Internet Explorer, but most of the same ideas still apply. The typical download prompt in IE looks like this:


#Instead of just sending the ENTER key, you will need to send a left arrow key first, and then ENTER to choose the “Save” option. In addition, the title of the page does not contain the name of the file. To get the name of the file, you will need to capture all the text from this window using the WinGetText function.

#You can now manipulate the character indices to pull out the file name.

Enhanced by Zemanta