Moh*_*ian 5 c# selenium cefsharp
我找到了这个https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver链接,其中有 cef 客户端和 Selenium 驱动程序的 java 绑定。
所以我准备了一个给我用 c# windows 应用程序使用它。我所做的是创建了一个新的 winapp 项目 x86,它只包含以下运行时没有错误或问题的代码:
using CefSharp;
using CefSharp.WinForms;
namespace ClientBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public ChromiumWebBrowser browser;
private void Form1_Load(object sender, EventArgs e)
{
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("enable-npapi", "1");
settings.IgnoreCertificateErrors = true;
//settings.CefCommandLineArgs.Add("enable-system-flash", "1");
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面的项目是作为下面新的winapp项目x86的cef客户端:
private void Form1_Load(object sender, EventArgs e)
{
try {
var options = new ChromeOptions();
options.BinaryLocation = @"path/ClientBrowser.exe";
//options.AddArgument("--log-level=3");
var service = ChromeDriverService.CreateDefaultService();
//service.HideCommandPromptWindow = true;
driver = new ChromeDriver(service,options); //chromedriver.exe
driver.Navigate().GoToUrl("http://stackoverflow.com/");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
现在当我运行上面的新项目时,
chromedriver.exe 说:
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 57883
Only local connections are allowed.
进而
ClientBrowser.exe 打开时没有显示任何内容,也没有遇到错误,但 60 秒后我得到:
The HTTP request to the remote WebDriver server for URL http://localhost:57883/session timed out after 60 seconds.
但它应该http://stackoverflow.com/为我打开,我不知道我做错了什么,我没有包括任何selenium-server-standalone-x.y.z.jar?我需要这个吗,如果是,请任何人告诉我如何包含它。
也试过用 Administrator Privilege
有没有办法直接绑定ChromeDriver使用ChromiumWebBrowser,所以就没有必要cefclient.exe
也试过RemoteWebDriver:
try {
var options = new ChromeOptions();
options.BinaryLocation = @"C:\pathto\ClientBrowser.exe";
options.AddArgument("--remote-debugging-port=1131");
options.AddArgument("url=data:,");
//options.AddArgument("--log-level=3");
var service = ChromeDriverService.CreateDefaultService();
//service.HideCommandPromptWindow = true;
service.Port = 1131;
service.Start();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(ChromeOptions.Capability, options);
driver = new RemoteWebDriver(service.ServiceUrl, capabilities); //DesiredCapabilities.Chrome()
//driver = new ChromeDriver(service,options); //chromedriver.exe
driver.Navigate().GoToUrl("http://stackoverflow.com/");
}
Run Code Online (Sandbox Code Playgroud)
但RemoteWebDriver也对我不起作用,现在真的卡住了,拜托了
任何帮助或建议对我和其他想像我一样做同样事情的人来说都是一个很大的帮助,提前致谢。
这是 Chromium 嵌入式框架的使用示例:
var service = ChromeDriverService.CreateDefaultService();
var options = new ChromeOptions();
options.BinaryLocation = @"C:\Users\florent\Downloads\Cef\cefclient.exe";
options.AddArgument("url=data:,");
var driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("https://www.google.co.uk");
Run Code Online (Sandbox Code Playgroud)
您可以在此处下载最新版本(测试应用程序):https ://cefbuilds.com/
| 归档时间: |
|
| 查看次数: |
7618 次 |
| 最近记录: |