selenium tutorial testing tools

Upload file using AutoIT

With the help of AutoIt tool (open source tool) we can upload by transferring the control from Selenium webdriver to AutoIt.

We need to explicitly call the AutoIt script from our program.

About AutoIT : AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

We need to call the AutoIt script after clicking on the upload button. Immediately after clicking on Upload button, the control should be transferred to AutoIt by the below statement which takes care of uploading the file .

Syntax:

Runtime.getRuntime().exec("AutoIt .exe filepath");

The below is the sample HTML source code with upload button:
File Upload AutoIt

If you observe the above screen shot, there are is no 'Input' html tag. Button is completely customized using css. Here we cannot send the file path using sendKeys method. Hence we should go for other Tool support to handle Operating System events

The below is the example code to call the AutoIt exe file.

package com.easy.upload;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class UploadFileAutoIt {

	static WebDriver driver;
	String URL = "C:\\Users\\Harry\\Desktop\\samplehtml.html";
	@Test
	public void testUpload() throws InterruptedException, IOException
	{
		driver = new FirefoxDriver();
		driver.get(URL);
		WebElement element = driver.findElement(By.name("file"));
		element.click();
		Runtime.getRuntime().exec("G:/Tutorial/AutoItScripts/upload.exe");
	}	
}

The below is the AutoIt script:

WinWaitActive("File Upload")
Send("G:\Tutorial\AutoItScripts\TestScripts\Test.doc")
Send("{ENTER}")
Selenium Tutorials: 

Comments

Hi,

I can able to upload single image using AutoIt. but when i'm trying to upload multiple images showing error "incorrect expression"..

nice to hear from you.

Hi,

I am curious what kind of tools can be use for mac? Because AutoIT is not available in mac, only for Windows.
Thanks.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.