我有以下AutoIT代码,我想知道如何迁移/转换为Java
的AutoIt:
AutoItSetOption("WinTitleMatchMode","20")
WinWait("Authentication Required")
While WinExists("Authentication Required")
Opt("SendKeyDelay", 50)
$title = WinGetTitle("Authentication Required") ; retrieves whole window title
$UN=WinGetText($title,"User Name:")
ControlSend($title,"",$UN,"myemail@gmail.com{TAB}");Sets Username and {TAB}
$PWD=WinGetText($title,"Password:")
ControlSend($title,"",$PWD,"mypassword");Sets PWD and {ENTER}
ControlSend($title,"",$PWD,"{ENTER}");
Sleep(2000)
WEnd
Exit
这是我尝试转换为Java:
public void shouldEnterCredentials() throws Throwable {
try {
File file = new File("lib", "jacob-1.18-x64.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
String title = x.winGetTitle("Authentication Required");
String un = x.winGetText(title,"User Name:");
String pwd = x.winGetText(title,"Password:");
x.autoItSetOption("WinTitleMatchMode","20");
x.winWait("Authentication Required");
while (x.winExists("Authentication Required")){
x.autoItSetOption("OPT_SEND_KEY_DELAY", "50");
x.controlSend(title,"", un, "myemail@gmail.com{TAB}"); //Sets Username and {TAB}
x.controlSend(title,"",pwd,"mypassword"); //Sets PWD and {ENTER}
x.controlSend(title, "", pwd,"{ENTER}");
x.sleep(2000);
}
} catch (Exception e) {
System.out.println("Error: " + e.getStackTrace());
}
}
有人可以帮助我吗?
答案 0 :(得分:3)
为什么不编译AutoIt代码并从Java代码运行它?
您的AutoIt代码没有返回任何内容,因此编译AutoIt脚本并从那里执行批处理文件更容易(也更可靠)。