1

I'm trying to upload a system file. To do this I use AutoIt, the following code is the script that I wrote to upload the file (an AutoIt script):

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare

Main()

Func Main()
    Local Const $dialogTitle = $CmdLine[2]
    Local Const $timeout = 5

    Local $windowFound = WinWait($dialogTitle, "", $timeout)

    $windowFound = WinWait($dialogTitle, "", $timeout)
    Local $windowHandle

    If $windowFound Then
        $windowHandle = WinGetHandle("[LAST]")
        WinActivate($windowHandle)

        ControlSetText($windowHandle, "", "[CLASS:Edit; INSTANCE:1]", $CmdLine[1])
        ControlClick($windowHandle, "", "[CLASS:Button; TEXT:&Open]")        
    Else
        MsgBox(0, "", "Could not find window.")
        Exit 1
    EndIf
EndFunc  

After this I compiled the script, the below script that I wrote to execute the .exe file created is:

Process process = new ProcessBuilder("C:\\Users\\selenium\\auto.exe",
                      "C:\\Users\\selenium\\test.png", "Open").start();   

There is a choose file button in my application, my test case is working untill clicking that button, after opening the system window. Then I'm not able to open the file with the directory specified above.

I'm using Selenium Web Driver Version -- 2.33 with FireFox version 21 and AutoIT version 2.28

4
  • Have you tried to directly type in to the file upload text field? Commented Aug 16, 2013 at 20:30
  • Yes Amey, but it it not working... Commented Aug 16, 2013 at 20:33
  • What do you mean by it is not working, do you get a Selenium Error? If yes whats the error? Commented Aug 16, 2013 at 20:33
  • I'm not getting any selenium error, the program is ending with no errors.. Amey Commented Aug 16, 2013 at 22:18

2 Answers 2

2

The "Open" argument refers to the window title, which is different from browser to browser. Chrome -"Open" Firefox - "File Upload" IE - "Choose File to Upload"

So, in your case, instead of this line -

Process process = new ProcessBuilder("C:\\Users\\selenium\\auto.exe", "C:\\Users\\selenium\\test.png", "Open").start();

You need to use:

 Process process = new ProcessBuilder("C:\\Users\\selenium\\auto.exe",
                      "C:\\Users\\selenium\\test.png", "File Upload").start();
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of using AutoIt to handle a file upload.. simply use IWebElement.SendKeys on the file input element, and the file upload dialog will be handled automatically for you.

So, instead of clicking on the file browser button...

Find the input element on the page where <input type="file"/>, and then create then create the appropriate locator to retrieve the element.

Then, use IWebElement.SendKeys() to this element with the full path of the file you want to upload.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.