提问人:Clonw 提问时间:11/13/2023 最后编辑:Clonw 更新时间:11/13/2023 访问量:27
SWT Shell 内部的 Selenium WebDriver EDGE
Selenium WebDriver EDGE inside SWT Shell
问:
我有一个 Java SWT 应用程序(版本 1.6),我在其中使用 swt。用于显示嵌入式浏览器的浏览器。但是,swt.浏览器基于 IE,我无法更新 SWT 以将浏览器与 EDGE 一起使用。
为了解决此问题,我们创建了一个并行的 Selenium WebDriver 应用程序,用于启动 EDGE 类型的浏览器。在 SWT 应用程序中,我检索了 EDGE 的 PID,并使用 org.eclipse.swt.internal.win32.OS 库,我设法将 EDGE 窗口设置为 SWT shell 的子窗口。
在 EDGE 窗口中,我可以用鼠标单击,但它不会捕获关键事件。关键事件在 SWT shell 中捕获。关于为什么关键事件没有在 EDGE 窗口中被拾取的任何想法?
在 Shell 的 open() 方法中,我们使用以下 java 代码来定位 EDGE 窗口
import org.eclipse.swt.internal.win32.OS;
//...
OS.ShowWindow(iWndMyWebDriver, OS.SW_HIDE);
OS.SetWindowLong(iWndMyWebDriver, OS.GWL_STYLE, OS.WS_CHILD & ~OS.WS_POPUP);
OS.SetParent(iWndMyWebDriver, handle);
int style = OS.GetWindowLongA(iWndMyWebDriver, OS.GWL_STYLE);
style = style & ~OS.WS_SYSMENU;
style = style & ~OS.WS_MAXIMIZEBOX;
style = style & ~OS.WS_MINIMIZEBOX;
style = style & ~OS.WS_CAPTION;
OS.SetWindowLongA(iWndMyWebDriver, OS.GWL_STYLE, style);
if (!isDisposed()) {
OS.SetWindowPos(iWndMyWebDriver, 0, -1, -2, getBounds().width, 495, 4 + 32);
}
OS.BringWindowToTop(iWndMyWebDriver);
RECT r = new RECT();
r.left = 0;
r.top = 0;
OS.RedrawWindow(iWndMyWebDriver, r, 0, 256 + 512 + 1 + 2 + 128);
OS.ShowWindow(iWndMyWebDriver, OS.SW_SHOW);
OS.SetForegroundWindow(iWndMyWebDriver);
if (!isVisible()) {
setVisible(true);
Pointer pHwnd = new Pointer(this.handle);
User32.INSTANCE.ShowWindow(pHwnd, 9);
User32.INSTANCE.SetForegroundWindow(pHwnd);
UtilsOS.SetWindowAlwaysOnTop(this.handle, true);
User32.INSTANCE.SetActiveWindow(pHwnd);
setFocus();
UtilsOS.SetWindowAlwaysOnTop(this.handle, false);
}
编辑: 我添加了以下代码:
addKeyListener( new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println( "key Released");
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println( "Key pressed");
}
});
当我将焦点放在 EDGE 上并按下一个键时,两个事件被捕获,我希望这些事件进入浏览器。
答: 暂无答案
评论