Hi, all today I am going to share small tricks for Autoit, Thanks to my friend Lajish Lakshmanan who gave me this tip. In this post, we will discuss how to pass parameters in Autoit script for Selenium code.
While uploading file in Selenium Webdriver using AutoIT we have hard coded the complete path so we cannot reuse that script for another test, which is actually bad practice.
We have to create a script in such way that we can reuse the scripts. In this case, we need to send parameters so that we can pass file in run time.
Please check below article before moving to passing parameter.
Solution for pass parameters to AutoIT script
We can accept command line parameter in runtime using below command.
In my previous post, I have already discussed that part using parameters we can upload multiple files without creating multiple scripts.
We can use & symbol to add values in AutoIT.
Program for pass parameters to AutoIT script
//Wait 15 seconds for the Upload window to appear(Comments)
//Set input focus to the edit control of Upload window using the handle returned by WinWait(Comments)
//Set the File name text on the Edit field. Last parameter will take file name on runtime(Comments)
ControlSetText(“File Upload”, “”, “Edit1”, “C:\FileUploads\Resume\”&$CmdLine)
Once you are done with script save the file > Compile the script > You will get the .exe file.
Program to call the file from Java program.
We have multiple ways to upload file in Selenium webdriver but you have to select which one will be best for you.
This is one of my short post but informative one, I hope you will implement in your project or in your future projects.
Please feel free to share your thoughts in comment section. Will see you in next post.