问题
I am doing automation using Selenium WebDriver and want to handle a browser authentication window. I know Selenium does not support this on its own but I am able to using AutoIt. We have to share our code with the client, so can AutoIt code be managed from Eclipse? This is the code:
WinWaitActive("Authentication Required", "", "120")
If WinExists("Authentication Required") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf
Code to run the AutoIt.exe from Eclipse:
Runtime.getRuntime().exec("C:\\NewAutoIT.exe");
Is there any way to manage AutoIt code from Eclipse?
回答1:
You should use library AutoItX4Java, it allows to execute AutoIt commands in Java.
You need to install AutoIt and use the library Java COM Bridge, then you can program directly in Java. I made a post on my site a while ago, but here is a simple example:
File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
String notepad = "Untitled - Notepad";
String testString = "this is a test.";
x.run("notepad.exe");
x.winActivate(notepad);
x.winWaitActive(notepad);
x.send(testString);
Assert.assertTrue(x.winExists(notepad, testString));
x.winClose(notepad, testString);
x.winWaitActive("Notepad");
x.send("{ALT}n");
Assert.assertFalse(x.winExists(notepad, testString));
来源:https://stackoverflow.com/questions/23590413/execute-autoit-code-from-eclipse