如何使用JNA单击IE软件下载栏中的“保存”按钮

时间:2018-02-25 18:32:43

标签: java windows internet-explorer jna

我有一个IE的下载栏: IE download bar

我需要找到一种方法来点击其中一个按钮或获取“运行”,“保存”或“取消”的位置 我正在使用Java和JNA,到目前为止代码看起来像这样:

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
import com.sun.jna.platform.win32.User32;

public class IEOperations {

    private static HWND wind;
    private static String title;

    public static HWND findWind(final String name) {
        final User32 user32 = User32.INSTANCE;
        title=null;
        wind = null;
        user32.EnumWindows(new WNDENUMPROC() {
            public boolean callback(HWND hWnd, Pointer arg1) {
                char[] windowText = new char[512];
                user32.GetWindowText(hWnd, windowText, 512);
                String wText = Native.toString(windowText);
                if (wText.contains(name)) {
                    title = wText;
                    wind = hWnd;
                    return false;
                }
                return true;
            }
        }, null);
        return wind;
    }

    public static String activate(String app) {
        User32 user32 = User32.INSTANCE;
        HWND hWnd = findWind(app);
        user32.ShowWindow(hWnd, User32.SW_SHOWMAXIMIZED);
        user32.SetForegroundWindow(hWnd);
        return title;
    }

    public static String getTitle(String app) {
        findWind(app);
        return title;
    }

    public static void main(String[] args) {
        System.out.println(activate("GitHub Desktop")); //Just test to show that code finds and activates window that I need.
        //TODO: Get Button objects and move cursor to those buttons and click... OR just click on "Save" button...
    }
}

上面的代码通过部分标题找到一个窗口并激活它。如何点击获取“保存”对象并单击它?

0 个答案:

没有答案