- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想嵌入 Selenium ChromeDriver
在 Windows 窗体面板中。我已成功关注 this example用于在 Windows 窗体中嵌入记事本。我认为我遇到麻烦的问题是获取 MainWindowHandle
来自 ChromeDriver
.这是我到目前为止所得到的:(完整代码的粘贴链接:https://pastebin.com/RNv2vbJ1)
//----------------------TEST---------------------
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
ChromeDriver driver = new ChromeDriver(service);
Console.WriteLine(driver.CurrentWindowHandle);
Process chromeDriverProcess = Process.GetProcessById(service.ProcessId);
//EmbeddedWindowHandle = driver.CurrentWindowHandle;
//----------------------TEST---------------------
ProcessStartInfo processInfo = new ProcessStartInfo("notepad.exe");
Process p = Process.Start(processInfo);
p.WaitForInputIdle();
EmbeddedWindowHandle = p.MainWindowHandle;
SetParent(EmbeddedWindowHandle, panel1.Handle);
MoveWindow(EmbeddedWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
SetWindowLong(EmbeddedWindowHandle, GWL_STYLE, WS_VISIBLE);
最佳答案
因此,嵌入控制台应用程序与您的方法有些相似,但并不相同。我发现很多线程都说这是不可能的或不起作用
How to embed a Console application inside a Winforms application
Embedding a DOS console in a windows form
Embedding a DOS console in a windows form with Visual Basic
并且有以下链接可以创建您自己的控件作为 CMD
https://www.codeproject.com/Articles/335909/Embedding-a-Console-in-a-C-Application
但我终于设法让下面的代码工作
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private IntPtr cmdPtr;
private int ConsoleWidth;
private IntPtr folderViewPtr;
private const int SWP_NOOWNERZORDER = 0x200;
private const int SWP_NOREDRAW = 0x8;
private const int SWP_NOZORDER = 0x4;
private const int SWP_SHOWWINDOW = 0x0040;
private const int WS_EX_MDICHILD = 0x40;
private const int SWP_FRAMECHANGED = 0x20;
private const int SWP_NOACTIVATE = 0x10;
private const int SWP_ASYNCWINDOWPOS = 0x4000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOSIZE = 0x1;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int WS_VISIBLE = 0x10000000;
private const int WM_CLOSE = 0x10;
private const int WS_CHILD = 0x40000000;
public abstract class WS
{
public const uint WS_OVERLAPPED = 0x00000000;
public const uint WS_POPUP = 0x80000000;
public const uint WS_CHILD = 0x40000000;
public const uint WS_MINIMIZE = 0x20000000;
public const uint WS_VISIBLE = 0x10000000;
public const uint WS_DISABLED = 0x08000000;
public const uint WS_CLIPSIBLINGS = 0x04000000;
public const uint WS_CLIPCHILDREN = 0x02000000;
public const uint WS_MAXIMIZE = 0x01000000;
public const uint WS_CAPTION = 0x00C00000; /* WS_BORDER | WS_DLGFRAME */
public const uint WS_BORDER = 0x00800000;
public const uint WS_DLGFRAME = 0x00400000;
public const uint WS_VSCROLL = 0x00200000;
public const uint WS_HSCROLL = 0x00100000;
public const uint WS_SYSMENU = 0x00080000;
public const uint WS_THICKFRAME = 0x00040000;
public const uint WS_GROUP = 0x00020000;
public const uint WS_TABSTOP = 0x00010000;
public const uint WS_MINIMIZEBOX = 0x00020000;
public const uint WS_MAXIMIZEBOX = 0x00010000;
public const uint WS_TILED = WS_OVERLAPPED;
public const uint WS_ICONIC = WS_MINIMIZE;
public const uint WS_SIZEBOX = WS_THICKFRAME;
public const uint WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW;
// Common Window Styles
public const uint WS_OVERLAPPEDWINDOW =
(WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_THICKFRAME |
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX);
public const uint WS_POPUPWINDOW =
(WS_POPUP |
WS_BORDER |
WS_SYSMENU);
public const uint WS_CHILDWINDOW = WS_CHILD;
//Extended Window Styles
public const uint WS_EX_DLGMODALFRAME = 0x00000001;
public const uint WS_EX_NOPARENTNOTIFY = 0x00000004;
public const uint WS_EX_TOPMOST = 0x00000008;
public const uint WS_EX_ACCEPTFILES = 0x00000010;
public const uint WS_EX_TRANSPARENT = 0x00000020;
//#if(WINVER >= 0x0400)
public const uint WS_EX_MDICHILD = 0x00000040;
public const uint WS_EX_TOOLWINDOW = 0x00000080;
public const uint WS_EX_WINDOWEDGE = 0x00000100;
public const uint WS_EX_CLIENTEDGE = 0x00000200;
public const uint WS_EX_CONTEXTHELP = 0x00000400;
public const uint WS_EX_RIGHT = 0x00001000;
public const uint WS_EX_LEFT = 0x00000000;
public const uint WS_EX_RTLREADING = 0x00002000;
public const uint WS_EX_LTRREADING = 0x00000000;
public const uint WS_EX_LEFTSCROLLBAR = 0x00004000;
public const uint WS_EX_RIGHTSCROLLBAR = 0x00000000;
public const uint WS_EX_CONTROLPARENT = 0x00010000;
public const uint WS_EX_STATICEDGE = 0x00020000;
public const uint WS_EX_APPWINDOW = 0x00040000;
public const uint WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
public const uint WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
//#endif /* WINVER >= 0x0400 */
//#if(_WIN32_WINNT >= 0x0500)
public const uint WS_EX_LAYERED = 0x00080000;
//#endif /* _WIN32_WINNT >= 0x0500 */
//#if(WINVER >= 0x0500)
public const uint WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
public const uint WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
//#endif /* WINVER >= 0x0500 */
//#if(_WIN32_WINNT >= 0x0500)
public const uint WS_EX_COMPOSITED = 0x02000000;
public const uint WS_EX_NOACTIVATE = 0x08000000;
//#endif /* _WIN32_WINNT >= 0x0500 */
}
public Form1()
{
InitializeComponent();
this.Width = 700;
this.ConsoleWidth = this.Width;
folderViewPtr = FindWindow("Progman", null);
folderViewPtr = FindWindowEx(folderViewPtr, IntPtr.Zero, "SHELLDLL_DefView", null);
folderViewPtr = FindWindowEx(folderViewPtr, IntPtr.Zero, "SysListView32", "FolderView");
//SetWindowLong(this.Handle, -8, (int)folderViewPtr); //GWL_HWNDPARENT
Process p = Process.Start("cmd.exe", "/k cd %userprofile%\\desktop");
Thread.Sleep(500); // Allow the process to open it's window
cmdPtr = p.MainWindowHandle;
SetParent(cmdPtr, this.Handle);
SetWindowLong(this.Handle, -20, (int)(GetWindowLong(this.Handle, -20) | WS.WS_CLIPCHILDREN ));
// Remove border and whatnot
SetWindowLong(cmdPtr, GWL_STYLE, (int)(WS.WS_VISIBLE ));
long exStyle = GetWindowLong(p.MainWindowHandle, GWL_EXSTYLE);
exStyle &= ~(WS.WS_EX_APPWINDOW | WS.WS_EX_CLIENTEDGE);
SetWindowLong(p.MainWindowHandle, GWL_EXSTYLE, (int)0);
MoveWindow(cmdPtr, -2, -2, this.ConsoleWidth, this.Height, true);
SetWindowPos(this.Handle, (IntPtr)1, this.Left, this.Top, this.Width, this.Height, 0);
timer1.Start();
}
protected override void WndProc(ref Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
const int WM_WINDOWPOSCHANGING = 0x0046;
switch (message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
{
//return;
}
break;
case WM_WINDOWPOSCHANGING:
SetWindowPos(this.Handle, (IntPtr)1, this.Left, this.Top, this.Width, this.Height, 0x0004);
Debug.Print("WM_WINDOWPOSCHANGING");
break;
}
base.WndProc(ref message);
}
protected override void OnResize(EventArgs e)
{
if (this.cmdPtr != IntPtr.Zero)
{
MoveWindow(cmdPtr, 0, 0, this.ConsoleWidth, this.Height, true);
}
base.OnResize(e);
}
protected override void OnHandleDestroyed(EventArgs e)
{
if (cmdPtr != IntPtr.Zero)
{
PostMessage(cmdPtr, 0x0010, 0, 0);
}
base.OnHandleDestroyed(e);
}
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool repaint);
[DllImport("User32.dll")]
static extern bool PostMessage(IntPtr hWnd, uint message, int wparam, int lparam);
[DllImport("User32.dll")]
static extern void SetActiveWindow(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern void SetWindowPos(IntPtr hWnd, IntPtr hWndNew, int x, int y, int cx, int cy, UInt32 uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hWnd, IntPtr hWndA, string lpClassName, string lpWindowName);
private void Form1_Load(object sender, EventArgs e)
{
this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right/2 - this.Width/2;
this.Top = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
//check if cmd still exists
if (!IsWindow(cmdPtr))
{
Application.Exit();
}
}
}
}
关于selenium - 在 Windows 窗体中嵌入 Selenium ChromeDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50181992/
我正在开发一个小型 Web 应用程序,其中有一个 object 元素(包含一个 embed),用于显示小型文档。 文档可以是 PDF 或纯文本文件 (.txt),我以 base64 字符串的形式从 W
我有一种小型语言,它基本上是 OCaml 的扩展(实际上它是 OCaml 子集的扩展,但这并不重要)。为了简化事情,我有一个“转义”表达式,可以将 OCaml 文字传输到我的语言中(因此您可以将任意
据我所知,我知道 embed tag用于嵌入来自 youtube 等网站的视频,object tag用于 Flash 视频和 video tags下HTML5 .但我很好奇这些标签的深入细节以及作为开
我假设您可以将 WebKit 嵌入到另一个桌面应用程序中并向其发送一个字符串,例如: Hello world! 它将显示在窗口内。 我的问题是,如果我将其压缩表示(JPEG 转储)加载到内存中,我该如
有没有一种可能的方式,我可以从youtube检索我的最新视频的列表(带有缩略图),使用cron作业将嵌入的代码存储在数据库中,这样我就可以在单独的页面上显示视频,而不是将用户引向youtube观看视频
最近我发现我的网站上嵌入的 YouTube 视频存在问题 - 全屏按钮不再起作用。确实有过一次。该按钮是可见的,但单击时没有任何反应。 我正在使用 Youtube Javascript API 将视频
在 Keras 内置函数中嵌入使用哪种算法?Word2vec?手套?其他? https://keras.io/layers/embeddings/ 最佳答案 简短的回答是都不是。本质上,GloVe 的
在 LSTM 上用于建模 IMDB 序列数据 ( https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py ) 的 ker
在机器学习中,通常用 one-hot-encoding 表示分类(特别是:名义)特征。 .我正在尝试学习如何使用 tensorflow 的嵌入层来表示分类问题中的分类特征。我有 tensorflow
我有一个使用 Storyboard的应用程序,我想在我的主视图中有一个 View ,并让它在场景中的不同 View 之间切换。 所以目前我有“容器对象”,我可以在其中嵌入另一个 viewControl
在我的项目中我遇到了这样的情况。 function fonsubmit() { alert('Out side PHP'); //Here the php code starts
我正在尝试添加一个JFileChooser,它选择父目录并允许用户输入文件名称。我知道 showSaveDialog 和 showOpenDialog 方法,但我不想创建新窗口。 这是我到目前为止所拥
我注意到我的网站创建了这样的链接:www.domain.com/post-name/embed/ 恐怕这可能会影响 SEO。是否可以禁用此功能? 最佳答案 显然这是默认的 WordPress 行为。此
我试图从 C 代码调用 python 函数,我遵循了 here 中的示例 我也有正确的包含文件目录、库目录和链接 python32.lib(我使用 python 32)但是错误是 python/C A
我正在使用基于云的 EDR 平台来监控客户端受损网络上发生的进程。我最近经常看到的是使用选项“-Embedding”调用的 msiexec.exe C:\Windows\System32\MsiExe
我有一个列表,其中包含数百万个需要嵌入的句子。我正在使用 Flair以此目的。这个问题似乎应该是并行的。但是,当我尝试优化时,我的性能要么没有提高,要么只是停滞不前。 我将我的句子定义为一个简单的字符
我想在我的应用程序中添加嵌入的 YouTube 视频:我该怎么做?我有这个 import 'package:youtube_player/youtube_player.dart'; import 'p
我有 json 看起来像: myjson = {"queries":{"F.SP": 27}} 所以与 queryResults = JObject.Parse(jsonString) 我可以 fir
我在 html 文档中嵌入 highcharts 饼图时遇到问题。具体来说,我无法在不更改图表大小的情况下调整图表容器的大小。有谁知道您是否可以在不缩小图表的情况下减少默认填充?或者,您可以在不增加容
我不太确定这在 MediaWiki 中是否可行。 我有几个类别,每个类别包含几页。如果您打开一个类别页面,您将看到该类别的内容,通常由以下三个部分组成: 用户定义的文本(可以使用编辑链接进行编辑)。
我是一名优秀的程序员,十分优秀!