Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What is Selenium?
3.
What is AutoIT?
4.
Setup of AutoIT
4.1.
Downloading and Installing AutoIT
4.2.
Downloading and Installing AutoIT Script Editor
5.
How to Use AutoIT?
5.1.
Use of AutoIT With Selenium
6.
Frequently Asked Questions
6.1.
What is the use of AutoIt in Selenium?
6.2.
What is the purpose of AutoIt?
6.3.
How to upload files using AutoIt in Selenium?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

AutoIT in Selenium

Introduction

Hello Ninjas. We know that Selenium is one of the best test automation frameworks. It is used for testing web applications. But there are also some limitations when using Selenium. It is not able to handle the operating system-level dialogs. It is also not able to automate the tasks that are outside the browser. This is where AutoIT comes into the picture.

AutoIT in Selenium

In this article, we will discuss about AutoIT in Selenium. We will discuss about why it is used. This blog will also help us to understand the steps of using AutoIT in Selenium. If you are a beginner with Selenium, you must have a doubt about what Selenium is. Before moving on to the main topic, let us understand about Selenium. 

What is Selenium?

Selenium is a widely used test automation framework. It is an open-source framework that makes it easy to use for everyone. It is primarily used for automating web browsers

Benefits of Selenium

Selenium is one of the most preferable frameworks. It provides various tools and libraries. That’s why it enables you to automate web applications across different browsers. It is supported by multiple programming languages(Java, Python, C#, etc)

What is AutoIT?

Selenium is one of the best automation frameworks. But it comes up with some limitations:

  • It cannot automate tasks at the OS level.
     
  • It cannot automate tasks outside the web browser.
     

These above-mentioned limitations can be addressed by AutoIT. AutoIT is one of the scripting languages that is designed for Microsoft Windows. It is also a freeware automation tool. It can automate tasks at the OS level. It comes up with simple syntax and various functions. It can also automate the tasks that are present outside the web browser. AutoIT helps testers in many ways:

  1. It allows you to interact with Graphical User Interface(GUI) elements.
     
  2. It can simulate the keyword and mouse actions.
     
  3. It can manipulate windows and dialogs.
     
  4. It can handle various actions(file uploads, file downloads, interaction with pop-up windows, etc.).
     

Now you might have a doubt about how we can use it on our system. Let us look at the setup of AutoIT.

Setup of AutoIT

Before using it directly, we need to set up AutoIT and AutoIT script editor on our local machine. 

Downloading and Installing AutoIT

First, we will follow below mentioned steps to download and install AutoIT:

Step 1: Go to the official site of AutoIT.

Setup of AutoIT

 

Step 2: Now, you need to go to downloads.

Setup of AutoIT

 

Step 3: Now, scroll down to the Download AutoIt button.

current versions of AutoIt

 

Step 4: Now, click on the Download AutoIt button to download the AutoIT.

Download Autolt


Step 5: Now, save it on your system.

Save on System

 

Step 6: Now, extract your downloaded file.

Extract File

 

Step 7: Now, open the extracted folder and install AutoIT.

Install AutoIT


Step 8: Now, accept the license agreement.

License Agreement


Step 9: Click on the next button until you get an install button. You need to choose the location where you want to install the AutoIT.

Install Location

 

Step 10: Now, click on the finish button.

Completing AutoIT Setup

Now, we are done with the installation of AutoIT. 

Downloading and Installing AutoIT Script Editor

Now, we need to install the AutoIT script editor so that we can write scripts in it. There are some steps to install the AutoIT script editor:

Step 1: Go to the official site of AutoIT.

official site of AutoIT

 

Step 2: Now, you need to go to downloads.

Click on Downloads

 

Step 3: Now, go to the Download Editor button. 

Download Editor button

 

Step 4: Now, click on the Download Editor button to download the editor.

AutoIT Script Editor

 

Step 5: Now scroll down to the .exe file and click on it.

exe file

 

Step 6: Now, click on the save button.

Click on Save Button

 

Step 7: Now click on the downloaded file and install the editor. You have to click on the next button until you don't see the finish button.

click on the next button

Now, we have downloaded and installed the AutoIT and AutoIT script editor. Now, you might have a doubt about how to use it. Let us discuss this.

How to Use AutoIT?

To use AutoIT, we need to follow some steps that are mentioned below:

Step 1: Go to the location where you have installed AutoIT. So, for us, it is C:\Program Files (x86)\AutoIt3

How to Use AutoIT

 

Step 2: Now, select and open Au3info.exe. It is an elements finder.

elements finder

Now we can drag and drop the finder tool to any website or web application. For example, 

elements finder

You can check this GIF, how the finder tool is getting information of a particular web page. We can use this finder tool to identify something on Windows by just simply dragging and dropping. Now you must be thinking of how to use it with Selenium. Let us consider an example of a website on which we need to upload something. So, we are taking the example of the file.io.

File.io

 

By clicking on the upload files button, we will see a different window:

Upload File Button

This is the thing we cannot test using Selenium. That’s why we need to use AutoIT and test. We need to write some script to test this thing.

 

Step 3: Now, open the AutoIT script editor. Go to C:\Program Files (x86)\AutoIt3\SciTE and open SciTE.exe.

AutoIT script editor

There are several commands that we can use in this editor, and a few of them are mentioned below:

  • ControlClick: It helps to simulate a mouse click on a particular window.
     
  • ControlFocus: It helps to set the input focus on a particular window.
     
  • ControlGetText: It helps to retrieve the text from a window.
     
  • ControlSetText: It helps to set the text of a window.
     

Step 4: Now, select any object that you want to work on. Suppose we are targeting the file name object.

targeting the file name

 

Step 5: Now, drag and drop the finder tool in the file name.

drop the finder tool

 

Step 6: Now, we have to write the script for the file name object.

ControlFocus("Open","","Edit1")
Sleep(4000)
ControlSetText("Open","","Edit1","C:\Users\naray\Downloads\autoit.jpg")
Sleep(4000)
ControlClick("Open","","Button1")

 

We have used several functions to perform the operation. These classes are given by the finder tool, as you can see in Step 5.

 

Step 7: Now, save the script with the .au3 extension.

au3 extension

 

Step 8: Now, we will compile the script.

compile the script

After compiling this, it will generate the executable file. To check whether the script is working properly or not, we can run the script.

executable file

Now, we got an executable file, and we can use this executable file with Selenium to perform this task. 

Use of AutoIT With Selenium

Now, we will understand how we can use the executable file in Selenium. There are some steps that we need to follow:

Step 1: Open Eclipse or any other IDE(Integrated Development Environment) and create a new Java project:

Open Eclipse

 

Step 2: Now, create a package CodingninjasAutoIT under src. Also, create a class SeleniumAutoITExample under the same package.

SeleniumAutoIT

 

Step 3: Now, we need to download the Selenium WebDriver, Server, and ChromeDriver to work on our project. Go to Selenium’s official website. Firstly, we will download the server:

Selenium WebDriver

Now, we have to download the WebDriver:

WebDriver

Finally, we will download the ChromeDriver:

ChromeDriver

After downloading all the things, you need to extract the files one by one.

If you have already installed it, then you can skip this step.

 

Step 4: Now, we need to add these jar files to our project. So, firstly we will add the server. So we need right click on the project, then go to build path, and then go to configure build path:

build path

Now, we have to click on Libraries and then add external jars:

add external jars

Now, we have to select the server jar from our downloaded location:

server jar

Now, we have to apply this jar to our project:

apply this jar

 

Step 5: Now, in our class SeleniumAutoITExample, we need to set the property and path of our ChromeDriver.

path of our ChromeDriver

 

Step 6: Now we need to write the following code in our class:

package CodingninjasAutoIT;

import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

//  Creating a class SeleniumAutoITExample
public class SeleniumAutoITExample {
		public static void main(String[] args) throws IOException, InterruptedException {
		// Set the path of our chrome browser
		System.setProperty("webdriver.chrome.driver", "C:\\Users\\naray\\Downloads\\chromedriver_win32\\chromedriver.exe");

		// Using the WebDriver
		WebDriver driver=new ChromeDriver();

		// Using file.io to upload file
        driver.get("https://www.file.io/");
        
        // Class Selector
        driver.findElement(By.className("e12cce780")).click();
        
        // Running executable file to perform the operation
		Runtime.getRuntime().exec("C:\\Users\\naray\\Downloads\\FileUploadScriptExample.exe");
		Thread.sleep(4000);
		driver.close();
		}
}

This will give us the following output:

following output

In this GIF, we can clearly see how Selenium is using the executable file to upload the file from the script.

Frequently Asked Questions

What is the use of AutoIt in Selenium?

AutoIT is a scripting language that is used in Selenium for automating OS-level tasks such as Windows-based pop-up windows, file uploads, and other non-browser interactions. It allows Selenium scripts to interact with desktop elements, enhancing test automation capabilities.

What is the purpose of AutoIt?

AutoIT is a scripting language and automation tool designed for Windows and its primary purpose is to automate tasks and interactions with Windows GUI elements, making it useful for automating desktop applications, and performing various system-related actions.

How to upload files using AutoIt in Selenium?

To upload files using AutoIT in Selenium, create an AutoIT script that opens the file upload dialog, navigates to the file, and simulates the "Open" button click. Then, call this script from your Selenium code using the Runtime.getRuntime().exec() method.

Conclusion

In this blog, we have discussed about AutoIT in Selenium. AutoIT is one of the important languages that is used in Selenium for scripting. We have discussed why it is used in Selenium, along with steps to use it. You can check out our other blogs to enhance your knowledge:

We hope this blog helped you to understand AutoIT in Selenium. You can refer to our guided paths on the Coding Ninjas Studio platform. You can check our course to learn more about DSA, DBMS, Competitive ProgrammingPythonJavaJavaScript, etc. 

To practice and improve yourself in the interview, you can also check out Top 100 SQL problems, Interview Experience, Coding interview questions, and the Ultimate guide path for interviews.

Live masterclass