C# 如何设置Selenium和ChromeDriver以无头模式运行

C# 如何设置Selenium和ChromeDriver以无头模式运行,c#,selenium,selenium-chromedriver,xunit,C#,Selenium,Selenium Chromedriver,Xunit,我正在尝试使用xUnit、Selenium和Chrome Canary(无头模式)运行浏览器测试,但不断出现以下错误: OpenQA.Selenium.WebDriverException The HTTP request to the remote WebDriver server for URL http://localhost:58692/session timed out after 60 seconds. 这是我的密码: var chromeOptions = new Chrome

我正在尝试使用xUnit、Selenium和Chrome Canary(无头模式)运行浏览器测试,但不断出现以下错误:

OpenQA.Selenium.WebDriverException
The HTTP request to the remote WebDriver server for URL 
http://localhost:58692/session timed out after 60 seconds.
这是我的密码:

var chromeOptions = new ChromeOptions
    {
        BinaryLocation = @"C:\Users\<USERNAME>\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
        DebuggerAddress = "127.0.0.1:9222"
    };

chromeOptions.AddArguments("no-sandbox", "headless", "disable-gpu");
_driver = new ChromeDriver(chromeOptions) {Url = Url};

取出调试器地址使其工作

var chromeOptions = new ChromeOptions
{
    BinaryLocation = @"C:\Users\<USERNAME>\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
};
var chromeOptions=新的chromeOptions
{
BinaryLocation=@“C:\Users\\AppData\Local\Google\Chrome SxS\Application\Chrome.exe”,
};

以防其他人在谷歌搜索时到达这里

对我来说,最有效的方法是从以下链接下载最新的chrome驱动程序:


快乐编码:)

非常有用,谢谢。我必须使用Chrome60测试版才能让它无头运行。
var chromeOptions = new ChromeOptions
{
    BinaryLocation = @"C:\Users\<USERNAME>\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
};
            case "chrome9515headless":
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddArgument("--headless");
                chromeOptions.AddArgument("--disable-gpu");
                chromeOptions.AddArgument("--disable-infobars");
                chromeOptions.AddArgument("--disable-extensions");
                chromeOptions.AddArgument("--window-size=1200,900");
                chromeOptions.AddArgument("--disable-browser-side-navigation");

                webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:9515"),
                    chromeOptions.ToCapabilities());
                break;
            case "chrome9515canary":
                ChromeOptions chromeOptionsCanary = new ChromeOptions();
                chromeOptionsCanary.BinaryLocation= @"C:\Users\********\AppData\Local\Google\Chrome SxS\Application\chrome.exe";
                //chromeOptionsCanary.AddArgument("--headless");
                //chromeOptions.AddArgument("--disable-gpu");
                chromeOptionsCanary.AddArgument("--disable-infobars");
                chromeOptionsCanary.AddArgument("--disable-extensions");
                chromeOptionsCanary.AddArgument("--window-size=1200,900");
                chromeOptionsCanary.AddArgument("--disable-browser-side-navigation");

                webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:9515"),
                    chromeOptionsCanary.ToCapabilities());
                break;