-1

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") Send("C:\Users\faris\Desktop\RP1.jpg") Sleep(2000) ControlFocus("File Upload","","Button1") Send("{Enter}")

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.SendKeys(Keys.Enter);
        Thread.Sleep(2000);
Process.Start("C:\\Users\\faris\\Desktop\\Autoit2.exe");

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

4 Answers 4

0

hi below is my working code just try this

Local $hWnd=WinWait("[CLASS:#32770]","",10)
ControlFocus($hWnd,"","Edit1")
Sleep(2000)
ControlSetText($hWnd, "", "Edit1", "D:\AutoiT\dropme.html")
Sleep(2000)
ControlClick($hWnd, "","Button1");
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

I faced the same problem few days back and solved the problem with the following code

Step 1: Autoit code is like

ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1","C:\Users\faris\Desktop\RP1.jpg")
ControlClick("File Upload", "", "Button1")

Step 2: Converted the .au3 into .exe file

Step 3: Integrated the above code in java like the following

Thread.sleep(2000L);
        Runtime.getRuntime().exec("C:\\Users\\faris\\Desktop\\Autoit2.exe");

Worked fine for me.

Comments

0

AutoIT script:


Local $hWnd=WinWait("[CLASS:#32770]","",10)

ControlFocus($hWnd,"","Edit1")

Sleep(2000)

ControlSetText($hWnd, "", "Edit1", "c:\FIRSTCRY.txt")

Sleep(2000)

ControlClick($hWnd, "","Button2");

Also make sure you are using the finder tool provided in the AutoIt pack for class information as :

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.