使用Java Access Bridge实现自动化 [英] Automation using Java Access Bridge

查看:4339
本文介绍了使用Java Access Bridge实现自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 Java Access Bridge 事件。我该怎么做:

I can capture text from UI controls (button/Editbox/Checkbox etc) in Java Applications, using Java Access Bridge events. How can I:


  1. 在编辑框中设置文字

  2. 点击按钮

使用Java Access Bridge API调用?

using Java Access Bridge API calls?

推荐答案

以下是我为项目所做的工作。创建一个基类API,将所有PInvokes调用到JAB WindowsAccessBridge DLL中。如果您使用的是64位操作系统,请确保定位正确的DLL名称。使用getAccessibleContextFromHWND函数从Windows句柄获取VmID和Context。通过枚举子项找到Java窗口中的文本框或按钮。一旦找到你正在寻找的控件,TextBox或Button就会执行操作。

Here is how I have done it for my project. Create a base class API that calls all PInvokes into JAB WindowsAccessBridge DLL. Make sure you target proper DLL Name if you are on 64 bit os. Use getAccessibleContextFromHWND function to get VmID and Context from Windows Handle. Locate the textbox or button within the Java Window by enumerating children. Once you locate the Control you are looking for in you case TextBox or Button perform the action.

1)设置文本

public string Text
{
    get 
    {
        return GetText();
    }
    set
    {
        if (!API.setTextContents(this.VmId, this.Context, value))
            throw new AccessibilityException("Error setting text");
    }
}

private string GetText()
{
    System.Text.StringBuilder sbText = new System.Text.StringBuilder();

    int caretIndex = 0;

    while (true)
    {
        API.AccessibleTextItemsInfo ti = new API.AccessibleTextItemsInfo();
        if (!API.getAccessibleTextItems(this.VmId, this.Context, ref ti, caretIndex))
            throw new AccessibilityException("Error getting accessible text item information");

        if (!string.IsNullOrEmpty(ti.sentence))
            sbText.Append(ti.sentence);
        else               
            break;

        caretIndex = sbText.Length;

    }

    return sbText.ToString().TrimEnd();
}

2)点击按钮

public void Press()
{
    DoAction("click");
}

protected void DoAction(params string[] actions)
{
    API.AccessibleActionsToDo todo = new API.AccessibleActionsToDo()
    {
        actionInfo = new API.AccessibleActionInfo[API.MAX_ACTIONS_TO_DO],
        actionsCount = actions.Length,
    };

    for (int i = 0, n = Math.Min(actions.Length, API.MAX_ACTIONS_TO_DO); i < n; i++)
        todo.actionInfo[i].name = actions[i];

    Int32 failure = 0;
    if (!API.doAccessibleActions(this.VmId, this.Context, ref todo, ref failure))
        throw new AccessibilityException("Error performing action");
}

核心......

public API.AccessBridgeVersionInfo VersionInfo
{
    get { return GetVersionInfo(this.VmId); }
}

public API.AccessibleContextInfo Info
{
    get { return GetContextInfo(this.VmId, this.Context); }
}

public Int64 Context
{
    get;
    protected set;
}

public Int32 VmId
{
    get;
    protected set;
}

这篇关于使用Java Access Bridge实现自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆