Faris Faris - 9 months ago 58
C# Question

Not able to upload a file using AutoIT script

I have searched thoroughly on this but in vain.
My issue is I have written the AutoIT script which works perfectly when its executed outside the C# or Java code.
The script is:

WinWaitActive("File Upload")
ControlFocus("File Upload","","Button1")

I made sure that my code is calling the same exact script.
When this script is executed in the program, The 'File Upload' dialog box opens up, I can see the file path is also displayed in the 'File name' field. but then the dialog box just quits and the file is not uploaded. technically the 'Open' button on the dialog box is not being clicked. Now, I have tried using the 'Control Click' command but its just the same.
I have also tried every type of Waits but its of no use. I am new to this and would really appreciate any kind of help.

Here's the code example:

IWebElement browse = driver.FindElement(By.Id("browse"));

"Browse" is the 'Upload file' button and sending an 'Enter' key invokes File upload dialog box in Firefox.

Answer Source

Okay, So some how I found the solution my self. I still don't know what is causing the failure. The way its working is I executed the AutoIT script 2 times in my code. The first time dialog opens up and quits as mentioned above but the second time the script is executed the file gets uploaded successfully.