controlClick不起作用

时间:2017-11-23 07:18:53

标签: java autoit

我正在尝试使用 AutoIt 自动化我的Java应用程序,但是我在点击某个按钮时遇到了困难。

我认为 AutoIt 知道控件的位置,如下所示,问题是它不会点击控件。

Java Application Screenshot

这是我的源代码......

    String jacobDllVersionToUse;
    if (System.getProperty("sun.arch.data.model").contains("32")) {
        jacobDllVersionToUse = "jacob-1.18-x86.dll";
    } else {
        jacobDllVersionToUse = "jacob-1.18-x64.dll";
    }

    System.out.println(jacobDllVersionToUse);

    File file = new File("autoit", jacobDllVersionToUse);
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

    AutoItX x = new AutoItX();
    String hWnd = "GfcEmulator-Hybrid";
    String exeDir = "C:\\GFC\\resources\\props";
    String exeName = "GFCEmulator_Automation.jar";

    Runtime.getRuntime().exec("cmd /c cd " + exeDir + " && " + exeName + "");
    x.winActivate(hWnd);
    x.winWaitActive(hWnd);

    x.ControlSetText(hWnd, "", "[CLASS:RichEdit20W; INSTANCE:1]", "____________");
    x.ControlSetText(hWnd, "", "[CLASS:RichEdit20W; INSTANCE:2]", "____________");
    x.ControlSetText(hWnd, "", "[CLASS:RichEdit20W; INSTANCE:3]", "____________");
    x.ControlSetText(hWnd, "", "[CLASS:RichEdit20W; INSTANCE:4]", "____________");

    x.controlClick(hWnd, "", "[CLASS:ComboBox; INSTANCE:1]");
    x.controlSend(hWnd, "", "[CLASS:ComboBox; INSTANCE:1]", "{down}+{enter}");

    x.sleep(1000);
    x.controlClick(hWnd, "", "[CLASS:Button; INSTANCE:1]"); // Click Connect Button, I already tried every method I know just to make this work but it all fails.

其他详细信息:

操作系统:Windows 10

按钮信息:

Connect Button Information

1 个答案:

答案 0 :(得分:1)

Auto IT在检测Java Swing中的控件方面有局限性

我通过遵循AutoIT论坛上的本指南找到了解决方法:Java UDF

此UDF为Java应用程序提供自动化支持。

该UDF当前可以自动执行独立的应用程序和基于浏览器的applet,这些应用程序是在Swing或Abstract Window Toolkit(AWT)中开发的。