How to configure Selenium and ChromeDriver to work in headless mode

I am trying to run browser validation using xUnit, Selenium and Chrome Canary (headless mode), but I keep getting this error:

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

      

Here's my code:

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};

      

I'm new to C #, so I'm not sure if I'm doing something flagrantly wrong, or if I'm just missing a setup. The error above stated that I need to set the debugger address and use a flag no-sandbox

, but none of them help.

Using these versions:

selenium 3.4
chromedriver 2.29
xunit 2.2

      

+3


source to share


3 answers


Extracting the debugger address made it work.



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

      

+3


source


In case others get here when searching on Google ...

What worked for me was to download the latest chrome driver from this link: https://sites.google.com/a/chromium.org/chromedriver/downloads



Happy coding :)

0


source


            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;

      

0


source







All Articles