Uploading & Downloading files in Selenium using AutoIT

Uploading & Downloading files in Selenium using AutoIT

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.

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

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Optimize Selenium WebDriver Automated Test Scripts: Speed

Optimize Selenium WebDriver Automated Test Scripts: Speed. Simple techniques to improve the execution speed of some automated test steps, up to 50X.

Automate drop-down menu and checkbox using Selenium 4.0

These drop-down menus contain the static values inside them. They don’t change with input from the user.

How to Perform Localization Testing Using Selenium WebDriver

In this post, we'll learn How to Perform Localization Testing Using Selenium WebDriver.

How To Get Attribute Value In Selenium WebDriver

How To Get Attribute Value In Selenium WebDriver. While you are automating your test cases with Selenium automation, here is how to start implementing Selenium getAttribute() method to get the best results.

How To Implement a JUnit Parameterized Test for Selenium Test Automation

Tired of writing the same test scripts for different input values? Save time by learning how to perform a parametrized test in JUnit. Don't miss this helpful article.