In one of my previous posts , we had seen about file upload using Robot class. This post is about uploading a file using the third party tool AutoIT.
Step1:
Launch http://www.toolsqa.com/automation-practice-form/
Step 2:
Under the section titled Profile Picture, click on the button named Choose File
Step3:
In the windows pop up for file upload, enter the path, where the file to be uploaded is present and hit enter.
Step1 and Step2 will be performed by the Webdriver script.
Step3 will be performed by the AutoIT script.
WebDriver script for this scenario:
public class ToolsQADemo {
public static void main(String[] args) throws InterruptedException,
IOException {
WebDriver driver = new FirefoxDriver();
driver.navigate()
.to("http://www.toolsqa.com/automation-practice-form/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
//We have to mention the path for the AutoIT script
Runtime.getRuntime().exec("D:/Selenium/AutoIt/Script/Script1.exe");
//Clicking on the element where the file is to be uploaded
driver.findElement(By.id("photo")).click();
}
}
AutoIT script for this scenario:
WinWaitActive("File Upload")
Send("D:\Pictures\abc.jpg")
Send("{ENTER}")
Note:
In the AutoIT script we have to mention the path of the file to be uploaded.
In the first line of the script which is ,WinWaitActive("File Upload") ,
"File Upload" is the name of the pop up that comes up. Make sure you give the same name as the windows pop up.
Pay It Forward...
DR