- Download and install AutoIT from https://www.autoitscript.com/site/autoit-script-editor/downloads/
- After installing it, you will see ‘Script Editor’ in the directory
- Open Script Editor and type as per below
Send(“D:\test\Selenium\Test.jpg”)
Send(“{ENTER}”)
- Now save the file as ‘sample’
- Right click on the saved file >> click ‘Compile script’
- ‘sample.exe’ file should be generated.
- Now to run this .exe file using java, Place this in your code.
- ‘ Runtime.getRuntime().exec(“D:\\test\\Project\\sample.exe”); ‘
- Please follow the below example for the reference.
public static WebDriver driver;
String URL = “www.someurl.com";
@Test
public void demoFileUploading() throws InterruptedException, IOException
{
driver = new FirefoxDriver();
driver.get(URL);
WebElement ele = driver.findElement(By.id(“id of attach button”));
ele.click();
Runtime.getRuntime().exec(“D:\\test\\Project\\sample.exe”);
}
}
Disadvantage :
- AutoIT supports only for windows.It wont support for ‘mac’