我想在Java中使用Selenium Webdriver自动进行测试。我正在自动下载文件部分,但无法处理在IE中下载时弹出的另存为对话窗口。通过单击链接IE显示从弹出窗口中保存或打开文件。
FROM microsoft/dotnet:2.1.2-runtime-alpine3.7 AS base
答案 0 :(得分:1)
自动下载:https://www.autoitscript.com/site/autoit/ 将其添加到Windows env变量内的路径中,以便可以在命令提示符下执行。
示例路径:
C:\ Program Files(x86)\ AutoIt3
这是处理自动it脚本的示例方法。
public static void saveFileInternetExplorer() throws Exception {
String pathToAutoItScript = "C:\\save_file_IE11.au3";
String command = "AutoIt3.exe " + pathToAutoItScript;
System.out.println("AutoIt command: " + command );
String output = new CommandLine(command).executeGetOutput();
if (output.contains("ERROR")) {
throw new Exception("AutoIt script error: " + output);
}
System.out.println(output);
}
用于在IE 11中保存文件的AutoIt脚本
Sleep(5000)
Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
If WinExists($hIE,"") Then
WinActivate($hIE,"")
ControlSend($hIE ,"",$hCtrl,"{F6}") ; Gives focus to Open Button
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{TAB}") ; Gives focus to Save Button
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{enter}") ; Submit whatever control has focus
EndIf
Sleep(3000)
单击下载按钮后,运行autoit3脚本,这将保存文件。
祝你好运!