Selenium with C# 55 - How to launch Chrome & Firefox browsers in headless mode in selenium using C#

Опубликовано: 10 Апрель 2026
на канале: Ankpro Training
7,705
45

What is ChromeOptions class?
What is FirefoxOptions class?
Test case execution using chrome in headless mode
Test case execution using Firefox in headless mode

#selenium #qa #testing #seleniumcsharp #chrome #chromeheadless #firefox #firefoxheadless #automation #tester #seleniumautomation #automationtesting #webdriver #softwaretesting

What is ChromeOptions class?
Class to manage options specific to OpenQA.Selenium.Chrome.ChromeDriver
public void AddArgument(string argument);
Adds a single argument to the list of arguments to be appended to the Chrome.exe command line.
Example :
ChromeOptions options = new ChromeOptions();             
options.AddArgument("--headless");

What is FirefoxOptions class?
Class to manage options specific to OpenQA.Selenium.Firefox.FirefoxDriver
public void AddArgument(string argument);
Adds a single argument to the list of arguments to be appended to the Firefox.exe command line.
Example :
FirefoxOptions options = new FirefoxOptions();             
options.AddArgument("--headless");

Possible Interview Questions on Chrome and firefox headless execution
What is a ChromeOptions class?
How to execute the test cases in Chrome Headless browser?
What is a FirefoxOptions class?
How to execute the test cases in Firefox Headless browser?


Program :

[TestMethod]
public void ChromeAndFirefoxHeadless()
{
//ChromeOptions options = new ChromeOptions();
//options.AddArgument("--headless");

FirefoxOptions options = new FirefoxOptions();
options.AddArgument("--headless");

IWebDriver driver = new FirefoxDriver(options);
driver.Url = "http://ankpro.com";

string s = driver.FindElement(By.ClassName("lead")).Text;

Console.WriteLine(s);

driver.Quit();
}