Hi...
First you can write a simple script in AutoIt and save the file as an executable(.exe).
Ex: attachFile.exe
AutoIt Code:
WinWaitActive("Choose file")
Send("C:\attach\samplefile.txt") \\location of the file you want to attach to the form and submit
Send("{ENTER}")
Java Code:
package com.company;
import java.io.IOException;
import com.thoughtworks.selenium.Selenium;
public class AddAttachment {
public static void attach(Selenium selenium, String fileName) {
try {
String[] commands = new String[]{};
commands = new String[]{"c:\\test\\attachFile.exe"}; //location of the autoit executable
Runtime.getRuntime().exec(commands);
} catch (IOException e) {}
//autoit executable is now waiting for a "Choose file" dialog to popup
selenium.click("name=browseButton");
//once the "Choose file" dialog is opened, the autoit will input the path and file name
}
}
Thanks,
NagarjunReddy K