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

2 回答 2

2

“打开”参数是指窗口标题,它因浏览器而异。Chrome - “打开” Firefox - “文件上传” IE - “选择要上传的文件”

所以,在你的情况下,而不是这条线 -

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

你需要使用:

 Process process = new ProcessBuilder("C:\\Users\\selenium\\auto.exe",
                      "C:\\Users\\selenium\\test.png", "File Upload").start();
于 2013-08-27T10:35:40.157 回答
1

而不是使用 AutoIt 来处理文件上传.. 只需IWebElement.SendKeys在文件输入元素上使用,文件上传对话框将自动为您处理。

所以,而不是点击文件浏览器按钮......

在 where 页面上找到输入元素<input type="file"/>,然后创建然后创建适当的定位器来检索该元素。

然后,IWebElement.SendKeys()将此元素与您要上传的文件的完整路径一起使用。

于 2013-08-19T20:39:22.573 回答