I want to write an AutoIt script for a file upload in my automation code in Eclipse. I am keeping my file to be uploaded in Project/resources/my_file.txt
.
I have written FileUpload.au3 as:
WinWait("File Upload","",10)
ControlFocus("File Upload","","Edit1")
Sleep(2000)
ControlSetText("File Upload" , "", "Edit1", "resources/my_file.txt")
Sleep(2000)
ControlClick("File Upload" , "","Button1");
If I compile the above file and create FileUpload.exe and call FileUpload.exe in my code, the problem is with the path of the file to be uploaded as that will differ system to system.
How do I get the absolute path of resources/my_file.txt and use that at runtime in my AutoIt script?
The special array $CmdLine is initialized with the command line parameters passed in to your AutoIt script. Note the scriptname is not classed as a parameter; get this information with @ScriptName instead. A parameter that contains spaces must be surrounded by "double quotes". Compiled scripts accept command line parameters in the same way.
$CmdLine[0] is number of parameters $CmdLine[1] is param 1 (after the script name) $CmdLine[2] is param 2 etc ... $CmdLine[$CmdLine[0]] is one way to get the last parameter...
So if your script is run like this:
AutoIt3.exe myscript.au3 param1 "this is another param"
$CmdLine[0] equals... 2
$CmdLine[1] equals... param1
$CmdLine[2] equals... this is another param
@ScriptName equals... myscript.au3
In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit
Here is how it should be done in your case:
WinWait("File Upload","",10)
ControlFocus("File Upload","","Edit1")
Sleep(2000)
ControlSetText("File Upload" , "", "Edit1", $CmdLineRaw)
Sleep(2000)
ControlClick("File Upload" , "","Button1");
Then you send a command line argument when you call compiled autoit
Run("FileUpload.exe resources/my_file.txt")