What is AutoIt
AutoIt is an open-source automation tool. Selenium web driver is used to automate the web application but, unlike selenium web driver it is used to automate the desktop application. It is a powerful tool, uses the combination of mouse events, keystrokes, and window controller to automate the window task, which is not possible in the selenium.
Steps to download and install
1. To download the AutoIt, Go to the link mentioned below and download it according to your system configuration.
2. Once, Download process completed install it.
3. Now, Open the AutoIt Editor: It is used to write the script.
“C:\Program Files (x86)\AutoIt3\SciTE\SciTE.exe”
and open the AutoIt identifier: It is used to identify the elements in the window application.
“C:\Program Files (x86)\AutoIt3\Au3Info.exe”
Create a script using the AutoIt
1. Open the AutoIt identifier.
2. Select the window button using the “Finder Tool” on the identifier. Select the “Finder Tool” and move to the button to perform the action.
Please follow the following steps to upload the images on the site.
a. Click on the “choose file” button on the site “https://al3.webnerserver.com/al3-viewer”.
b. Move the “Finder Tool” button to the File name field.
c. Open the editor and write the code, ”ControlFocus()” method for the File name.
This method focuses on the file name in the file uploader.
First parameter title is “Open”.
Ignore the second parameter class.
Third parameter controller Id is the combination class = “Edit” and instance = “1”.
d. Use the “ControlsetText()” method to open the Image.
In this method, we will pass the Image path with parameters.
e. Now select the open button with “Finder Tool” button.
F. Use the “Controlclick()” to click on the open button.
After writing the script, Save the script and compile the script, because without compiling the script we cannot use this script. We have two options to compile the script ” compile script x64 ” and ” compile script x86 “. if you have windows 32-bit machine then you go with ” compile script x86 ” and for windows 64-bit machine then u go with ” compile script x64″.
Use file upload script with selenium
To upload a file using the selenium, we need to click on the “Choose file button” using selenium and then use the AutoIt compiled script by using: Runtime.getRuntime().exec(“File Path”); Code.
1. Runtime: class allows the script to interface with the environment in which the script is running.
2. getRuntime(): get the current runtime associated with this process.
3. exec() methods: execute the AutoIT script ( FileUpload.exe ) .
Please see the below screenshot. How to use the AutoIt script in the selenium.