Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I want to try out headless chrome, but I am running into this issue, that I can't start the driver in headless mode. I was following google documentation. am I missing something? The code execution gets stuck in var browser = new ChromeDriver(); line

Here is my code:

var chromeOptions = new ChromeOptions

{

    BinaryLocation = @"C:\Users\2-as Aukstas\Documents\Visual Studio 2017\Projects\ChromeTest\ChromeTest\bin\Debug\chromedriver.exe",

    DebuggerAddress = "localhost:9222"

};

chromeOptions.AddArguments(new List<string>() {"headless", "disable-gpu" });

var browser = new ChromeDriver(chromeOptions);

browser.Navigate().GoToUrl("https://stackoverflow.com/");

Console.WriteLine(browser.FindElement(By.CssSelector("#h-top-questions")).Text);

1 Answer

0 votes
by (62.9k points)
  1. Add 2 libraries via NuGet like the image shown below

image

2. Try below Code:

String url = "http://www.google.com";

var chromeOptions = new ChromeOptions();

chromeOptions.AddArguments(new List<string>() { "headless" });

var chromeDriverService = ChromeDriverService.CreateDefaultService();

ChromeDriver driver = new ChromeDriver(chromeDriverService, chromeOptions);

driver.Navigate().GoToUrl(url);

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...