AutoIT in selenium is a third-party tool. With the help of AutoIt tool (open-source tool), we can upload and download files. 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.
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI (Graphical User Interfaces) and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g., VBScript and SendKeys). AutoIt.
Steps to Download AutoIt in selenium: –
1) Go to AutoIt website (https://www.autoitscript.com) and navigate to download page. It will display the latest version. The top most download is for AutoIt, click on it.
2) It will open a pop-up box, click on ‘Save File‘ button.
3) Once the download is complete, double click on the .exe file and it will ask for our agreement on their terms and condition. Click on ‘I Agree‘ button.
4) Complete the process and click on the ‘Finish‘ button at the end of the installation.
In AutoIT, we can parameterized ControlSetText method. And passed required string to ControlSetText method as below:
Wait for 10 seconds for upload window
Local $winId=WinWait(“[CLASS:#32770]”,””,10);
set focus In FileName field ControlFocus($winId,””,”Edit1″) Sleep (1000);
send file name to upload
ControlSetText ($winId,””,”Edit1″,”C:UsersAdminDesktopAutoIt File UploadNew Microsoft Publisher Document.pub”)
Sleep (2000);
click on open Button ControlClick ($winId,””,”Button1″)
Save autoIt file with extension .au3. After that it should be converted in exe format. (Tool->Click on Build- Automatically converted in exe format on location)
Program- Uploading File Through AutoIT Tool: –
String url=”https://demoqa.com/automation-practice-form”; BaseUtilities bu=new BaseUtilities ();
WebDriver driver=bu. startupUsingWM (url, “Ch”);
WebElement PopUp=driver.findElement(By. cssSelector(“img[alt=’adplus- dvertising”));
PopUp.click();
WebElement Ele=driver.findElement(By.id(“uploadPicture”)); bu. clickByJs(Ele, driver);
Runtime.getRuntime().exec(“E:\Sheetal- Acceleration\Software\Maven\Path_Maven Project\Nov_9_seleinum\AutoIT\chromeupload.exe”);