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.

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.

Wanted Contributers

Hello Viewer! We're a relatively a small group of writers who have combined efforts to write the articles. Well, we need more help from talented people to contribute and grow the size of articles. It's great work if you're looking for a little money on the side – make this as your Part time job.

We are mainly looking into Protractor, Cucumber, JBehave, RSpec, Behat Mink, Selenium Python or any other tool which uses selenium.

If you can contribute on any the above, Please contact us.