Friday, July 3, 2020

Handling File Upload from Windows using AutoIT

Problem to solve

From below website i need to upload pdf file

https://www.freepdfconvert.com/pdf-to-jpg







To solve this we can use AutoIT tool.


What is AutoIt?

Automating the Windows-Desktop GUI

How to Download?

https://www.autoitscript.com/site/autoit/downloads/







To build the script 





Now we have to write script for

1.Shift focus to file upload window


2.Set path into filename edit box



3.click open to upload file





To spy the window objects

Click on Au3Info_x64.exe


C:\Program Files (x86)\AutoIt3



Below are the steps:







Write your scripts here








1.Shift focus to file upload window
ControlFocus("Open","","Edit1")




Similarly write for other

2.Set path into filename edit box

ControlSetText("Open","","Edit1","D:\UPC\Selenium\sample.pdf")

3.click open to upload file


ControlClick("Open","","Button1")


So all 3 elements are inspected and scripts are ready




save with filename







Now right click on the above file





click on compile script (x86)

now we see below exe file gets created








TO INVOKE .exe

Runtime.getRuntime().exec("D:\\UPC\\Selenium\\AutoIt\\fileUpload.exe");



code for above:


package automationTest;

import java.io.IOException;

import org.omg.SendingContext.RunTime;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;

import io.github.bonigarcia.wdm.WebDriverManager;

public class LoginLogout1 {
public static void main(String[] args) throws InterruptedException, IOException {
//System.setProperty("webdriver.chrome.driver","D:\\UPC\\Selenium\\Repository\\Project1\\drivers\\chromedriver1.exe");
        WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.freepdfconvert.com/pdf-to-jpg#");
Thread.sleep(3000);
driver.findElement(By.xpath("//div[contains(text(),'Choose PDF file')]")).click();
Thread.sleep(3000);
Runtime.getRuntime().exec("D:\\UPC\\Selenium\\AutoIt\\fileUpload.exe");

}
}

2 comments:

Selenium_Grid_With_Docker_Compose(yml file)

 docker-compose.yml version: "3" services:   hub:     image: selenium/hub:3.141.59     ports:       - "4444:4444"   chro...