Home Java Overview Maven Tutorials

Sunday 28 April 2024

Selenium Integration with AutoIT

Hello Friends,

In this article we will learn about open source tool AutoIT which is used to automate window bases application.
1). Download and install AutoIT
2). Different Components in AutoIT
3). Basic commonds in AutoIT
4). Reading window based popup properties using AutoIT
5). Seenium Integration with AutoIT
6). html script for choose me file

Download and install AutoIT in window based PC
open the and type Download AutoIT
click on link
now go to download section as below

zip file will be downloaded, please unzip it and click on application (.exe) file and install as simple software installation

Accept the Licence Agreement

Select as per your operating system

Select edit the script option so that we can edit the script

Keep it as a default setting and click on next

Select the destination folder

Install the software

click the finish button

w indo click on window start button and see the AutoIT and its components are installed as below

Three Main AutoIT components are

1). SciTE Script Editor
like as other editor ike eclipse, Intellij Idea, this is editor for AutoIT commonds

2). AutoIT Window Info
By this we can get the info like "Title", "body", "Id" etc of target window, which we can use in our script
once scripting completed we will save the file with extention .au3

3). Run Script
Now by this runner we will open our saved file and run them

Basic Commonds in AutoIT

All The commonds are very easy and avaiable at autoit website
But here is few important commonds which we mostly use in our selenium Automation
1)Run : Runs an external Program
Syntax :

Run("program", "workingdir"(optional), "show_flag"(optional), "opt_flag"(Optional))

For example : Open a notpage


For Example: Open a notepad with window maximized
Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

2)WinWait : Pauses execution of the script until the requested window exists.
Syntax :

WinWait("title", "text"(Optional), "timeout"(optional))

For Example : Open a notepad and wait for 5 seconds

WinWait("[CLASS:Notepad]", "", 5)

3)WinWaitActive : Pauses execution of the script until the requested window is active.
Syntax :

WinWaitActive("title", "text"(Optional), "timeout"(optional))

For Example : Open a notepad and wait for 5 seconds
WinWaitActive("[CLASS:Notepad]", "", 5)

Tips : The window is polled every 250 milliseconds or so.

4) Sleep : Pause script execution
Syntax :

Sleep(Amount of time to pause(in millisecond))

Example : Sleep(3000)

5) Send : Sends simulated keystrokes to the active window.
Syntax :

Send ("keys", flag(optional))

Example 1:
press window + r
type notepad.exe and press Enter key


Example 2:
Send raw text
Send("welcome at")
Example 3 :
Press Enter
Example 4:
Press Escape key
Send{ESCAPE} or Send{ESC}

6) WinClose : Closes a window

WinClose("title", "text"(Optional))

or Example :
Open a Notepad
Enter some text and close it
WinWaitActive("Untitled - Notepad")
Send("welcome at")
WinClose("*Untitled - Notepad")

7) ControlFocus : Sets input focus to a given control on a window.
Syntax :

ControlFocus("title", "text(text of window to access)", controlID)

8) ControlSetText : Sets text of a control.
Syntax :

ControlSetText("title", "text(text of window to access)", controlID, "new Text( The new text to be set into the control)", flag(optional))

9)ControlClick : Sends a mouse click command to a given control.
Syntax :

ControlClick("title", "text(text of window to access)", controlID, button(optional), clicks(optional), x(optional) , y(optional))

AutoIT Window Infoby this tool we will read the attributes of popup window
first read the edit text part of the window

now read the button attribute

Now AutoIT script will be like this

Now right click on saved .au3 file and choose option "compile script(64bit)"

Now Integrate this AutoIT script to our selenium script

Runtime.getRuntime().exec("complete path of above compiled file upto exe");

Scenarios : Suppose we have scenario that we need to
1) : Open the browser
2) : Open the practice page
3): click the button "Choose File" , window based popup will open
4) : now enter the complete path of file in input box of popup
5) : click on Open button

import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Capturepopup {
WebDriver driver;
public void launch() throws InterruptedException {
System.setProperty("", "./Driver\\chromedriver.exe");
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
System.setProperty("", "true");
ChromeOptions options = new ChromeOptions();
// options.addExtensions(new File("/path/to/extension.crx"));
// WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);
// driver = new ChromeDriver();

public void TestAutoIt() throws InterruptedException, IOException {
WebElement element = driver.findElement(By.xpath("//input[@type = 'file']"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView();", element);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
Actions act = new Actions(driver);

Below is html script for demo of AUTOIT

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Choose File Example </head>

<h2 style = "color:blue">Welcome at</h2>
<h2>Choose File Example</h2>
<!-- Button to trigger file input -->
<button onclick="chooseFile()">Choose File</button>
<!-- Hidden file input -->
<input type="file" id="fileInput" style="display: none;">
// Function to trigger file input when button is clicked
function chooseFile() {
// Function to handle file selection
document.getElementById('fileInput').addEventListener('change', function() {
var file = this.files[0];
if (file) {
console.log('Selected file:', file);
// You can perform further operations with the selected file here
} else {
console.log('No file selected');
}); </script>

#AutoIT Tutorials

# AutoIT integration with selenium

#AutoIT Commonds