Skip to main content

Desktop Automation using AutoIT in C# Visual Studio 

By January 18, 2024February 8th, 2024Blogs, QA, Testing

What is AutoIT ? 

AutoIt is a scripting language and window-based application automation tool. 

Pros: 

  • Windows Automation: AutoIt is great for automating Windows applications. It allows your C# application to do things like clicking buttons and typing text in other programs. 
  • Easy to Learn: AutoIt’s scripting language is easy to understand. It’s good for people who want to automate Windows tasks without learning complex programming languages. 
  • Useful Functions: AutoIt has built-in functions for many tasks, including working with GUIs (Graphical User Interfaces), files, and the clipboard. 
  • Script Recording: AutoIt can record your actions and turn them into automation scripts, which is helpful for beginners. 

Cons: 

  • Windows Only: AutoIt works only on Windows. You can’t use it for automation tasks on other operating systems like Linux or macOS. 
  • Limited for Web: While you can use AutoIt with web browsers, it’s not the best choice for web automation tasks compared to other tools. 
  • Script Compilation: To run AutoIt scripts, you need to compile them into executable files. This adds an extra step when you want to deploy your automation. 
  • Security Concerns: Some security software might mistakenly flag compiled AutoIt scripts as harmful, causing false alarms. 
  • Learning Curve: Though AutoIt is easy to get started with, mastering it for complex tasks might take some time. 

Installation Steps: 

  1. AutoIT Installation:  

Step 1: Download & Install Finder Tool from Link 

File Type: .zip 

Use: To Find Window Elements 

Step 2: Download & Install Script Editor i.e SciTe Tool from Link 

File Type: .exe 

Use: To write Script for Window  Automation 

Step 3: You can see AutoIT Folder appears under ‘All Apps’ 

Step 4: Click on AutoIT Finder Tool (According to your system property i.e. x64 / x84) 

Step 5: AutoIT Finder Tool will open 

Step 6: Now again access Stsrt menu & go to ‘AutoIT’ folder. Now click  on AutoIT Scripting Tool ‘SciTE’ (According to your system property i.e. x64 / x84) 

Step 7: AutoIT Finder Tool will open 

Step 8: Open Chrome & load Web Application URL i.e. Register (automationtesting.in) 

Step 9: Click on ‘Choose file’ 

Step 10: Below window will appear 

Step 11: Now Open SciTE Script Editor & write Basic Code 

// To focus on opened window 

ControlFocus(“”,””,”Edit1″) 

// To set text on Element 

ControlSetText(“”,””,”Edit1″,””) 

// To click on Element 

ControlClick(“”,””,””) 

Step 12: Now Open Web Application & AutoIT Finder tool  

Step 13: Now move this pointer tool to other element 

Step 14: Now I moved the pointer to ‘File Name’ Element & we can see Finder tool got the details. So now we copy value from ‘ClassnameNN’ field 

Step 15: Now paste the copied value to SciTE Scripting Tool 

Step 16: Now Open Web Application & AutoIT Finder tool  

Step 17: Now copy the ‘Title’ value i.e ‘Open’ & paste it in SciTE Tool  

Step 18: Now Open Web Application & AutoIT Finder tool  

Step 19: Now right click on the file which you want to upload & copy file path 

Step 20: Now paste the Value in SciTE Tool  

Step 21: Now open Web Application & AutoIT Finder tool then Locate another Element2 i.e ‘Open’ button. Copy the Element value ‘Button1’ from finder tool 

Step 22: Now paste the Value in SciTE Tool  

Step 23: Now click on save icon to Save this File 

Step 24: Now give file name & file type will be saved as ‘.au3’ then click on save button 

Step 25: Now open the folder location where ‘.au3’ file is saved 

Step 26: Now Right click on Upload file & click on Compile Script (You Can choose x64 / x84 bit according to your system) 

Step 27: We can see .exe file is generated (We need this .exe file path in our code) 

  1. Creating Project in Visual Studio:  

Step 1: Launch Visual Studio or download and install it if you haven’t already. 

Step 2: Open Visual Studio 

Step 3: Click on ‘Create a new project’ 

Step 4: Below window will open 

Step 5: Choose Project Template “Console App” for C# & click on Next button 

Step 6: Give your project a name and specify the location where you want to save it. 

Step 7: Click the “Next” button 

Step 8: Choose “Framework” to create your new C# project and click on “Create” button 

Step 9: Project Screen will appear 

Step 10: Right-click on Your Project 

Step 11: Click the “Browse” section and search for “Selenium.WebDriver” 

Step 12: Install latest “Selenium.WebDriver” 

Step 13: Open “Program.cs” file & paste below code in it 

using OpenQA.Selenium; 

using OpenQA.Selenium.Chrome; 

using OpenQA.Selenium.Interactions; 

using System.Diagnostics; 

public class Program 

    public static void Main() 

    { 

        // To initialize & launch the driver 

        IWebDriver driver = new ChromeDriver(); 

        // To call action class methods 

        Actions a = new Actions(driver); 

        // Load the URL 

        driver.Navigate().GoToUrl(“http://demo.automationtesting.in/Register.html”); 

        // Maximize the Browser Window 

        driver.Manage().Window.Maximize(); 

        // Stop the execution for 5 seconds (5000 miliseconds) 

        Thread.Sleep(5000); 

        // To click on “Choose File” button 

        a.MoveToElement(driver.FindElement(By.XPath(“//input[@id=’imagesrc’]”))).Click().Build().Perform(); 

        // Wait for some time (5000 milliseconds) 

        Thread.Sleep(7000); 

        // Use Process.Start to run the AutoIt script for file upload 

        string executablePath = @”E:\Demo\Upload2.exe”; // Paste actual path of .exe file which we have created 

        // To start AutoIt program execution 

        Process.Start(executablePath); 

        // Wait for some time (5000 milliseconds) 

        Thread.Sleep(5000); 

        // Close the WebDriver 

        //driver.Quit(); 

    } 

Step 14: Build the code & Run It! 

Sales Inquiry
close slider