问题
I'm trying to run chrome headless using selenium in C# but I keep getting this error:
You are using an unsupported command-line flag: --ignore-certificate-errors, Stability and security will suffer.
I'm using
- Chrome: 61
- ChromeDriver: 2.3
- Selenium: 3.6
- .Net 4.5
My code:
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);
}
}
}
My WinForm application just has one button with name "StartBtn".
回答1:
To get rid of the following error :
You are using an unsupported command-line flag: --ignore-certificate-errors, Stability and security will suffer
As you are using Selenium: 3.6
along with Chrome: 61
, instead of using chromedriver v2.3
consider using the latest version of the chromedriver.exe
i.e. v2.33
Additionally, along with your existing arguments add the following arguments as well: disable-infobars
, --disable-extensions
So, the line of code will be as follows:
options.AddArguments("headless", "disable-gpu", "remote-debugging-port=9222", "window-size=1440,900", "disable-infobars", "--disable-extensions")
来源:https://stackoverflow.com/questions/46789261/how-to-address-you-are-using-an-unsupported-command-line-flag-ignore-certifi