selenium测试用JNAUtils

来源:互联网 发布:免流网站源码 编辑:程序博客网 时间:2024/06/10 04:49
public class JNAUtils {// char数组转为Stringpublic static String char2String(char[] cs) {StringBuffer sf = new StringBuffer();for (char c : cs) {if (c != '\0')sf.append(c);}return sf.toString();}// 枚举窗体public static void listTitles() {User32.INSTANCE.EnumWindows(new WNDENUMPROC() {int count;public boolean callback(HWND hWnd, Pointer userData) {String title = getTitle(hWnd);count++;if (!title.equals("")) {System.out.println("total " + count);System.out.println(hWnd);System.out.println(title);// System.out.println(getUnitFrameWnd(title));}return true;}}, null);}
// 枚举子窗体public static void listItems(HWND window) {if (window == null)return;User32.INSTANCE.EnumChildWindows(window, new WNDENUMPROC() {int count;public boolean callback(HWND hWnd, Pointer userData) {String title = getTitle(hWnd);count++;if (!title.equals("")) {System.out.println("total " + count);System.out.println(hWnd);System.out.println(title);// System.out.println(getUnitFrameWnd(title));}return true;}}, null);}public static List<HWND> getWindows() {final List<HWND> items = new ArrayList<HWND>();User32.INSTANCE.EnumWindows(new WNDENUMPROC() {int count;public boolean callback(HWND hWnd, Pointer userData) {String title = getTitle(hWnd);count++;if (!title.equals("")) {items.add(hWnd);}return true;}}, null);return items;}
public static List<HWND> getItems(HWND window) {if (window == null)return null;final List<HWND> items = new ArrayList<HWND>();User32.INSTANCE.EnumChildWindows(window, new WNDENUMPROC() {int count;public boolean callback(HWND hWnd, Pointer userData) {// String title=getTitle(hWnd);count++;items.add(hWnd);return true;}}, null);return items;}// 由窗体名称获取句柄public static HWND getUnitFrameWnd(String windowTitle) {HWND hwnd = User32.INSTANCE.FindWindow(null, windowTitle);return hwnd;}// 设置为焦点public static void setFocus(HWND hwnd) {if (hwnd == null)return; // 窗口不存在while (isMin(hwnd)) {System.out.println("窗口最小化,已还原");User32.INSTANCE.ShowWindow(hwnd, User32.SW_NORMAL);}while (!hwnd.equals(getACtiveHwnd())) {System.out.println("设焦点");User32.INSTANCE.SetForegroundWindow(hwnd);}}



原创粉丝点击