Java 使用Selenium和AutoIt通过远程桌面实现自动化
我想自动化某些需要它完成的任务 我将分享到现在为止我写的代码Java 使用Selenium和AutoIt通过远程桌面实现自动化,java,selenium,autoit,Java,Selenium,Autoit,我想自动化某些需要它完成的任务 我将分享到现在为止我写的代码 public class MainClass { static WebDriverWait wait; static WebDriver driver; public static void main(String args[]) { driver = new HtmlUnitDriver(true); driver.get("https://mysite"); WebElement subm
public class MainClass
{
static WebDriverWait wait;
static WebDriver driver;
public static void main(String args[])
{
driver = new HtmlUnitDriver(true);
driver.get("https://mysite");
WebElement submit_element=driver.findElement(By.id("Log_On"));
driver.findElement(By.id("Enter user name")).sendKeys("my_username");
driver.findElement(By.name("passwd")).sendKeys("my_password");
submit_element.click();
driver.findElement(By.id( "folderLink_0")).click();
driver.findElement(By.id( "folderLink_2")).click();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
System.out.println(driver.getPageSource());
driver.findElement(By.id("idCitrix.M")).click();
System.out.println(driver.getPageSource());
}
}
代码行
`driver.findElement(By.id("idCitrix.M")).click();`
在新窗口中打开远程桌面
线路
`System.out.println(driver.getPageSource());`
is retrieving the same code in both places.
我相信这不能完全靠硒来实现。通过浏览互联网,我了解到使用互联网是可以做到这一点的
如何操作?Selenium可用于自动化web浏览器的部件,而AutoIT应用于自动化Windows应用程序(在您的情况下,它可能会登录到远程计算机) 此链接提供了有关如何与Selenium一起使用AutoIT的详细信息: 以下是您必须做的: 下载/安装AutoIT
您将能够使用AutoITSciTe编辑器创建.au3脚本 编译.au3脚本将得到一个.exe文件 然后,您可以使用从Selenium脚本调用.exe文件
Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");
您可以使用自动IT窗口信息(x86)或(x64)获取窗口的属性。例如,窗口的标题/状态栏
AutoIT还有Au3记录器,以便您可以记录与远程桌面相关的操作
下面是一个自动化Http身份验证的示例脚本:
WinWaitActive("Web page title","","10")
If WinExists("Web page title") Then
Send("userid{TAB}")
Send("password{Enter}")
EndIf
下面的脚本获取记事本状态栏中的文本:
WinWaitActive("Untitled - Notepad", "", 30)
Local $hWnd = WinGetHandle("Untitled - Notepad")
Local $sText = StatusbarGetText("Untitled - Notepad","",2)
ConsoleWrite($sText)
我希望这些信息有帮助
更新:
进一步搜索后,发现此库AutoITx4Java-
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));
您好……谢谢您的时间……但是在eclipse中使用AutoIt库不能做到吗?仅供参考,这里可以找到一种仅使用Selenium API将Selenium与AutoIt集成的替代方法:到目前为止,您的答案是什么?据我所知,即使AutoIt自动化了Windows,它也可能无法通过远程桌面会话对Windows对象工作。要处理此问题,您需要在连接到的实际远程桌面计算机上运行AutoIt,而不是在使用远程桌面(客户端)的web浏览器计算机上运行AutoIt。