LDTP doc: 

https://ldtp.freedesktop.org/user-doc/

对于 web 自动化,我们用 Selenium, 但是对于 windows 控件,我们可以使用 LDTP。

首先,需要引用的 jar 包。

CobraWinLDTP-3.0.0.msi (这个是需要安装的,安装到 C:\Program Files (x86)\VMware\CobraWinLDTP, 而核心的文件就是
CobraWinLDTP.exe。也就是它真正操作了 windows 控件。) 

commons-codec-1.6.jar
commons-logging-1.1.2.jar
LDTP.jar
ws-commons-util-1.0.2.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar

上面第一个是安装 vmware 的 LDTP。

Ldtp不需要安装 python,也不需要安装 jep,它只需要外部有 CobraWinLDTP.exe,并按照 client-server 的方式工作。ldtp.jar是client,先通过启动进程的方式运行CobraWinLDTP.exe,然后通过xmlrpc协议,把java的命令变成调用CobraWinLDTP.exe的命令,从而可以识别控件、操纵控件

(对,java调用pywinauto时,需要依赖jep这个桥梁来把java的命令变成python端的,jep就是负责传递命令的)

由于 CobraWinLDTP.exe 是 server 端,所以先需要在命令行中启动 CobraWinLDTP.exe。

然后看代码:

package ldtp;

import com.cobra.ldtp.Ldtp;

public class TestLdtp {
    public static void main(String[] args) {
        Ldtp ldtp = new Ldtp("abc");
        String[] wins = ldtp.getWindowList();
        for (String win : wins)
        {
            System.out.println(win);
        }
    }
}

====打印结果====

paneTaskbar
frmEclipse SDK
frm?????? - ??? - Mozilla Firefox
frmNew Tab
frmWeChat
frmD:\EclipseSpaceNew\LdtpTestNew\lib
frmC:\Program Files (x86)\VMware\CobraWinLDTP
frmAdministrator: Command Prompt - CobraWinLDTP.exe
frmUntitled - Paint
lst0
paneProgram Manager

上面代码中的 "abc" 是随便一个名字。这段代码可以打印出所有的 frame。然后你找到你需要的,就可以继续操作了。

下面是打开 notepad 后一些操作的代码

package ldtp;

import com.cobra.ldtp.Ldtp;

public class TestLdtp {
    public static void main(String[] args) {
        String winStr = "frmUntitled - Notepad"; //Open Notepad first please
        Ldtp ldtp = new Ldtp(winStr);
        String[] wins = ldtp.getWindowList(); //Print all windows
        for (String win : wins)
        {
            System.out.println(win);
        }
        ldtp.activateWindow(winStr);
        System.out.println("=================");
        String[] objects = ldtp.getObjectList(); //Print all objects
        for (String ob : objects)
        {
            System.out.println(ob);
        }
//        ldtp.click("mnuView"); //This can click the View menu
        ldtp.selectMenuItem("View;Status Bar"); //Click View > Status Bar
        ldtp.appendText("txtTextEditor", "hello allen");
    }
}

====打印结果====
paneTaskbar
frmEclipse SDK
frmUntitled - Notepad
frm?????? - ??? - Mozilla Firefox
frmNew Tab
frmslc12dkq-16-2012-OBIEEServer - Remote Desktop Connection Manager v2.2
frmD:\sw\UIAVerify2.0_x86
frmNow Playing
frmAdministrator: Command Prompt - CobraWinLDTP.exe
frmD:\00????
pane1
pane2
paneChatContactMenu
lst0
paneProgram Manager
=================
txtTextEditor
uknVertical
btnLineup
btnLinedown
uknHorizontal
btnColumnleft
btnColumnright
ukn2
ukn3
lbl0
lblLn1,Col1
ukn4
mnuSystem
mnuSystem1
btnMinimize
btnMaximize
btnClose
mnuApplication
mnuFile
mnuEdit
mnuFormat
mnuView
mnuHelp

关于 LDTP 操纵 windows 控件。的更多相关文章

  1. 在web中使用windows控件,实现摄像头功能

    最近做的一个Web版的视频会议项目,需要在网页中播放来自远程摄像头采集的实时视频,我们已经有了播放远程实时视频的使用C#编写的windows控件,如何将其嵌入到网页中去了?这需要使用一种古老的技术,A ...

  2. 在Web中使用Windows控件

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+] 将Net控件转化为ActiveX控件 1GUID 2实现IObjectSafety接口 3程序集设定 制作安装程序 Web集 ...

  3. 向ArcGIS的ToolBarControl中添加任意的windows控件的方法

    概要:在使用ArcEngine开发中,给ToolbarControl添加按钮形式的命令项相信大家都很熟悉了,因为网上的例子很多.但这种使用click调用功能的方式只能满足大部分用户在体验方面的需求,除 ...

  4. ArcGIS ElementLayer上放置Windows控件

    ElementLayer是ArcGIS API for Silverlight/WPF中的一种图层类型,主要用来承载Silverlight/WPF中的UIElement对象(UIElement),使用 ...

  5. 在Web中如何使用Windows控件(ActiveX)[转]

    最近做的一个Web项目,需要在网页中播放摄像头采集的实时视频,我们已经有了播放视频的使用C#编写的windows控件,如何将其嵌入到网页中去了?这需要使用一种古老的技术,ActiveX. 1.将.Ne ...

  6. Delphi对象变成Windows控件的前世今生(关键是设置句柄和回调函数)goodx

    ----------------------------------------------------------------------第一步,准备工作:预定义一个全局Win控件变量,以及一个精简 ...

  7. 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用

    Dixon 原文  用ArcGIS Engine.VS .NET和Windows控件开发GIS应用     此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...

  8. [修正] Berlin Firemonkey Windows 控件左方显示虚线问题

    说明:在 Wndows 显示时,有时控件左方会显示一条虚线 适用:Berlin Firemonkey 修正方法: 请将源码 FMX.Platform.Win.pas 复制到自己的工程目录里,再进行修改 ...

  9. windows控件理论学习

    mmp快考试了还在浪 一.对话框编辑器创建控件 1.使用new在堆上创建,系统结束时我们需要使用delete去销毁控件 2.对话框编辑器控件,程序结束,自动销毁 二.控件类的基类 CWnd类和消息映射 ...

随机推荐

  1. k-means 非监督学习聚类算法

    非监督学习 非监督学习没有历史样本数据和标签,直接对数据分析或得结果. k-means 使用 >>> from sklearn.cluster import KMeans >& ...

  2. ERROR qos-server can not bind localhost:22222

    dubboe版本2.7.1 spring cloud alibaba最新官网examples 根据readme中说明文档依次启动 1.nacos,默认用户名密码nacos/nacos 2.启动spri ...

  3. LInux安装MySQL5.7.24详情

    安装包下载 MySQL 的官网下载地址:http://www.mysql.com/downloads/ 我安装的是5.7版本 第二步: 选择:TAR (mysql-5.7.24-el7-x86_64. ...

  4. Linux分布式消息队列RocketMQ部署与监控--双Master

    环境准备:CentOS_6.5_x64 IP: 192.168.0.249 dbTest249  Master1 IP: 192.168.0.251 webTest251 Master2 下载 ali ...

  5. 从FBV到CBV二(认证器)

    span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...

  6. Delphi Edit组件

  7. deep_learning_Function_tensorflow_transpose()

    tf.transpose()的用法 一.tensorflow官方文档内容 transpose(     a,     perm=None,     name='transpose' ) Defined ...

  8. ISO/IEC 15444-12 MP4 封装格式标准摘录 2

    目录 Track Media Structure Media Box Media Header Box Handler Reference Box Media Information Box Medi ...

  9. 解决 android studio 出现:"AndroidStudio:Could not GET 'https://dl.google.com Received status code 400 from server: Bad Request"问题

    一.android studio 编译项目时出现"AndroidStudio:Could not GET 'https://dl.google.com Received status cod ...

  10. .net Core的例子

    阅读文章: 十二个 ASP.NET Core 例子