Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java访问桥c#无法激活字段、设置文本、单击等_C#_Automation_Java Access Bridge - Fatal编程技术网

Java访问桥c#无法激活字段、设置文本、单击等

Java访问桥c#无法激活字段、设置文本、单击等,c#,automation,java-access-bridge,C#,Automation,Java Access Bridge,我在c#中的Java访问桥上工作了一段时间。 我终于在一定程度上实现了这一目标 我可以正确初始化访问桥 我可以使用GetAccessibleContextFromHWND获取vmid和javaObjectHandle 我还可以使用GetAccessibleContextInfo来获取accessibleContextInfo 最后,我可以列举子节点并找到我感兴趣的节点 从那里我该怎么办? 我尝试了设置文本、单击或获取文本等操作,但失败。 我使用了另一个问题中提到的以下代码 设置文本: pub

我在c#中的Java访问桥上工作了一段时间。 我终于在一定程度上实现了这一目标

  • 我可以正确初始化访问桥
  • 我可以使用GetAccessibleContextFromHWND获取vmid和javaObjectHandle
  • 我还可以使用GetAccessibleContextInfo来获取accessibleContextInfo
  • 最后,我可以列举子节点并找到我感兴趣的节点
从那里我该怎么办? 我尝试了设置文本、单击或获取文本等操作,但失败。 我使用了另一个问题中提到的以下代码

设置文本:

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;

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

    }
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 void Press()
{
动作(“点击”);
}
受保护的void操作(参数字符串[]操作)
{
API.AccessibleActionsToDo todo=新API.AccessibleActionsToDo()
{
actionInfo=新API.AccessibleActionInfo[API.MAX\u ACTIONS\u TO\u DO],
actionScont=actions.Length,
};
for(inti=0,n=Math.Min(actions.Length,API.MAX\u actions\u TO\u DO);i
任何想法都将不胜感激。
谢谢

doAccessibleActions
实际上,此函数根本不起作用,因此,您必须结合win32 api来执行其他操作,例如:
设置文本
=>
发送键
,滚动