2017-10-17 96 views
0

我想在C#中使用硒运行Chrome的无头,但我不断收到此错误:无头的Chrome与硒在C#

You are using an unsupported command-line flag: --ignore-certificate-errors, Stability and security will suffer.

我使用

  • Chrome:61
  • ChromeDriver:2.3
  • Selenium:3.6
  • .NET 4.5

我的代码:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Chrome; 

namespace MyApp { 
public partial class Form1: Form { 
    public Form1() { 
     InitializeComponent(); 
    } 

    private void StartBtn_Click(object sender, EventArgs e) { 
     string appPath = AppDomain.CurrentDomain.BaseDirectory; 

     IWebDriver driver; 
     ChromeOptions options = new ChromeOptions(); 
     options.AddArguments("--headless", "--disable-gpu", "--remote-debugging-port=9222", "--window-size=1440,900"); 
     driver = new ChromeDriver(options); 
    } 
} 
} 

我的WinForm应用程序只是有名称为 “StartBtn” 一个按钮。

+0

你可能想使用phantomjs尝试代替。 –

+1

@RichBryant Chrome比PhantomJs更稳定,性能更好。 – Raven

+0

有争议。幻象确实倾向于使用命令行选项更好地播放。 –

回答

0

为了摆脱以下错误:

You are using an unsupported command-line flag: --ignore-certificate-errors, Stability and security will suffer

当您使用Selenium: 3.6Chrome: 61沿,而不是使用chromedriver v2.3考虑使用最新版本的chromedriver.exev2.33

此外,连同现有的参数添加下面的参数,以及:disable-infobars--disable-extensions

因此,该行代码将如下:

options.AddArguments("headless", "disable-gpu", "remote-debugging-port=9222", "window-size=1440,900", "disable-infobars", "--disable-extensions") 
+0

没有工作,它仍然显示错误。 – Raven

+0

用版本信息更新了我的答案。一探究竟。 – DebanjanB

+0

谢谢,更新了chromedriver的工作。 – Raven