我使用TestNG框架和Selenium進行Web UI測試。我有一個文件下載對話框,我想單擊並使用AutoIT。AutoIT腳本不會從我的Java代碼中執行任何操作
這裏是我的腳本來處理Firefox的題爲「開放」
Opt("WinTitleMatchMode", -2)
If $CmdLine[0] < 2 Then
ConsoleWrite("Usage: " & @ScriptName & " <Opening> <timeout in seconds>" & @CRLF)
Exit(1)
EndIf
; File save dialog is titled "Opening <file>" in Firefox and "File Download" in IE.
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title $timeout = $CmdLine[2]
; wait until dialog box appears
If WinWait($title, "", $timeout) Then ; match the window with substring
;ConsoleWrite("Found File save dialog" & @CRLF)
WinActivate($title)
Send("!S")
ControlClick("Opening", "", "[TEXT:&OK]")
Exit
Else
ConsoleWrite("File save dialog did not appear after " & $timeout & " seconds" & @CRLF)
Exit(2)
EndIf
這是我的Java代碼和路徑AutoIt的exe文件已經被添加到系統路徑FIEL對話框。但問題是,代碼似乎沒有做任何與該exe文件,它執行該行並進入下一個,但文件對話框仍然像無法識別。
final String type = getWebDriver().getClass().getName();
if (type.toLowerCase().contains("firefox")) {
exe = "SelectFileDialogOptions.exe";
commandLine = exe + " Opening " + 15;
} else {
//handle IE
}
logger.info("Executing the command '" + commandLine + "'...");
try {
final String[] commands = commandLine.split(" ");
Runtime.getRuntime().exec(commands);
} catch (final IOException e) {
throw new WebTestControllerException(
"Caught exception while trying to execute command '"
+ commandLine
+ "'. Exception is: "
+ e.getMessage());
}
嘗試將您的'ConsoleWrite()'改爲'MsgBox()'來試圖看看它有多遠。 –
試過這個,但執行exe時的結果相同。當我手動嘗試它時,即打開文件對話框,然後從命令行運行AutoIT腳本,然後我可以看到ConsoleWrite/Msgbox顯示出來,但它仍然沒有點擊對話框,可能是因爲它無法「 t獲得焦點.. – Jai