It will help you to have a Setup the AutoIT tool in window machine and also help to Uploading & Downloading files in Selenium using AutoIT in window GUI.

Prerequisites
  • Java as the programming language
  • AutoIT as the automation tool
  • Maven as the build tool
  • WebDriver as the browser automation tool
  • IntelliJ as the IDE

What is AutoIt?

  • AutoIt is a scripting language implemented for windows GUI automation. Using the combination of simulated keyboard, mouse movement, and window/control manipulation to automate tasks not possible using only selenium. So use of AutoIt tool, We will Uploading & Downloading the files in Selenium.

Why Use AutoIt?

  • Selenium is an open source tool that is designed to automate web-based applications on different browsers but to handle window GUI and non HTML popups in application. To handle such elements like Windows authentication box, File upload dialog box, and any other non-browser interaction we use AutoIt.

How to download and install the AutoIT

  • Go to the link https://www.autoitscript.com/site/autoit/downloads/
  • Scroll down and Click on the “Download AutoIt”.
  • Install the AutoIT tool.
  • After installation completion – open up AutoIT Editor.
  • Go to C:\Program Files (x86)\AutoIt3\SciTE\SciTE
  • Click on the “SciTE” Application, The AutoIT editor opens as shown in the below screen.
  • Now opens the element Identifier.
  • Go to C:\Program Files (x86)\AutoIt3\Au3info_x64.

Upload the file using AutoIt Script in Selenium WebDriver

  • Open the Programs – Autoit tool – SciTE Script Editor and include the below mentioned AutoIt script in Autoit editor and save it as ‘UploadFile.au3’ in your system.
  • Convert it as ‘UploadFile.exe’.
  • add the below mentioned Selenium Script and run.

Step 1: Open SciTE Script editor and add the below mentioned AutoIt script and save it as ‘UploadFile.au3’ in your system.

AutoItScript

ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\Users\PrajjawalK\Music\check\visit.pdf")
ControlClick("Open","","Button1")

AutoItScript Explanation

  1. ControlFocus(” title “,” text “,controlID )
  2. Above the line of code changes the focus to the file upload windows.
  3. ControlSetText(” title “,” text “,controlID ,” File path which need to upload ” )
  4. set text/path into file name edit box.
  5. ControlClick(” title “,” text “,controlID )
  6. click open to upload file.

Step 2: Once the file is saved.

Step 3: Now we need to convert the ‘UploadFile.au3’ to ‘UploadFile.exe’. So Right-click on the file ‘UploadFile.au3’ and click on ‘Compile Script(x64)’ to generate an executable file ‘UploadFile.exe’.

**Step 4: **Add the below selenium script and run.

package Autoit;

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

public class FileUpload {

    public static void main(String[] args) throws InterruptedException, IOException {
        //Instantiation of driver object. To launch chrome browser
        System.setProperty("webdriver.chrome.driver","C:\\Users\\PrajjawalK\\Downloads\\Upload_Download\\Upload_Download\\chromedriver.exe");

        WebDriver driver=new ChromeDriver();
        driver.get("https://www.ilovepdf.com/pdf_to_word");
        driver.manage().window().maximize();
        driver.findElement(By.cssSelector("a[id='pickfiles']")).click();
        Thread.sleep(3000);
        //To call the AutoIt script
        Runtime.getRuntime().exec("C:\\Users\\PrajjawalK\\Music\\check\\Fileupload.exe");
        driver.close();
    }

}

#java #quality assurance (qa) #testing #automation #selenium webdriver

Uploading & Downloading files in Selenium using AutoIT
1 Likes1.65 GEEK