主要问题:如何在C#中为CEFsharp应用程序配置selenium?
如果有人遇到将selenium配置到CEFsharp应用程序的问题,请看一下这篇文章。我度过了一段艰难的时光,并在互联网上搜寻这一切,我希望与其他人分享这些信息。
我的环境:
这是解决方案:
确保您的应用程序使用RemoteDebugging(在主程序文件中):
static void Main()
{
var cefSettings = new CefSettings
{
WindowlessRenderingEnabled = true,
MultiThreadedMessageLoop = true,
BrowserSubprocessPath = @"CefSharp.BrowserSubprocess.exe",
LogSeverity = LogSeverity.Error,
};
cefSettings.CefCommandLineArgs.Add("--disable-pinch", "1");
#if DEBUG
**cefSettings.RemoteDebuggingPort = port#;**
#endif
Cef.Initialize(cefSettings);
如果使用angular,请确保包含(在clientshellwinforms部分中):
#if DEBUG
_webView.Load("http://localhost:portForAngular");
#endif
要连接到selenium上的应用程序,请使用:
public void Main()
{
var chromeDriverService = ChromeDriverService.CreateDefaultService();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("remote-debugging-port=port#");
chromeOptions.DebuggerAddress = "localhost:port#";
driver = new ChromeDriver(chromeDriverService, chromeOptions);
}
然后你应该能够驾驶使用硒。
需要考虑的事项:
只要应用程序启用了远程调试,您就可以打开它然后运行selenium函数。
使用chrome:// inspect(代替或调试器端口)来充分利用开发工具。
掘金:
祝好运!