简体   繁体   English

使用Selenium和AutoIt通过远程桌面自动化

[英]Automate through a remote desktop using Selenium and AutoIt

I want to automate certain tasks which needs it to go through Remote Desktop Connection . 我想自动执行需要通过远程桌面连接的某些任务。

I will share the code which I wrote till now. 我将分享到目前为止我写的代码。

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());
  }
}

The line of code 代码行

`driver.findElement(By.id("idCitrix.M")).click();`

opens the remote desktop in a new window. 在新窗口中打开远程桌面。

The line 这条线

`System.out.println(driver.getPageSource());`
is retrieving the same code in both places.

I believe this cannot be done solely by Selenium. 我相信这不能仅由Selenium完成。 By browsing through the Internet I learnt it is possible to do this using AutoIt . 通过浏览互联网,我了解到可以使用AutoIt完成此操作。

How can I do it? 我该怎么做?

Selenium can be used for the parts that are automating your web browser whereas AutoIT should be used for automating Windows applications (in your case, its probably logging into the remote machine). Selenium可用于自动化Web浏览器的部件,而AutoIT应用于自动化Windows应用程序(在您的情况下,它可能会登录到远程计算机)。

This link provides good information on how to use AutoIT alongwith Selenium: http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/ 此链接提供了有关如何与Selenium一起使用AutoIT的详细信息: http//www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

Here is what you have to do: 这是你要做的:

Download/install AutoIT 下载/安装AutoIT
You will be able to create .au3 scripts using AutoIT SciTe Editor Compiling the .au3 script will give you a .exe file Then you can invoke the .exe file from your Selenium script using 您将能够使用AutoIT SciTe Editor创建.au3脚本编译.au3脚本将为您提供.exe文件然后您可以使用Selenium脚本调用.exe文件

Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");

You can get the properties of a window using the AutoIT Window Info (x86) or (x64) . 您可以使用AutoIT窗口信息(x86)或(x64)获取窗口的属性。 Example, title / status bar of a window. 示例,窗口的标题/状态栏。

AutoIT also has Au3 Recorder so that you can record your actions that are related to the remote desktop. AutoIT还具有Au3记录器,以便您可以记录与远程桌面相关的操作。

Below is a sample script that automates Http authentication: 下面是一个自动执行Http身份验证的示例脚本:

WinWaitActive("Web page title","","10")
If WinExists("Web page title") Then
Send("userid{TAB}")
Send("password{Enter}")
EndIf

Below script gets the text present in the status bar of Notepad: 下面的脚本获取记事本状态栏中的文本:

WinWaitActive("Untitled - Notepad", "", 30) 
Local $hWnd = WinGetHandle("Untitled - Notepad")
Local $sText = StatusbarGetText("Untitled - Notepad","",2)
ConsoleWrite($sText) 

I hope this information helps! 我希望这个信息帮助!

Update : Upon further searching, found this library AutoITx4Java - https://code.google.com/p/autoitx4java/ 更新 :进一步搜索,找到此库AutoITx4Java - https://code.google.com/p/autoitx4java/

  1. Download Jacob, AutoIT (refer the above link) 下载雅各布,AutoIT(参考上面的链接)
  2. Add jacob.jar and autoitx4java.jar to your library path. 将jacob.jar和autoitx4java.jar添加到库路径中。
  3. Place the jacob-1.15-M4-x64.dll file in your library path. 将jacob-1.15-M4-x64.dll文件放在库路径中。

Sample Code 示例代码

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Selenium-WebDriver 通过 AutoIt 上传多个文件 - Multiple file upload through AutoIt using Selenium-WebDriver 使用AutoIt的Chrome身份验证-桌面锁定情况 - Chrome Authentication using AutoIt - Desktop locked situation 如何通过Java使用Selenium自动执行自动建议菜单 - How to automate auto-suggestive menu using Selenium through Java 如何通过台式机应用程序使用硒测试网页? - How to test a web page using selenium through a desktop application? 如何通过Selenium中的AutoIt脚本动态上传文件? - How to upload file Dynamically through AutoIt Script in Selenium? 在SOAP UI中自动运行请求:如何将值从Java硒代码传递给自动代码 - Automate running requests in SOAP UI: How to pass a value from Java selenium code to an autoit code 使用Selenium自动登录Web应用程序 - automate log in to a webapplication using selenium 如何在不使用autoit且仅使用selenium和java的情况下上传文件? - How to upload a file without using autoit and with only using selenium and java? 无法使用sikuli自动化桌面应用程序 - Not able to automate desktop application using sikuli 使用AutoIt通过Selenium WebDriver中的窗口提示上载文件 - Upload file via window prompt in Selenium WebDriver using AutoIt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM