Site Loader
Auckland, New Zealand
In this post we are going to discuss about running Chrome in headless mode with Selenium C#

Chrome headless

Headless Chrome is a way to run Chrome browser without the actual browser UI being spawned. Essentially its running Chrome without chrome! It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line and automation testing tool such as Selenium in our case

Where is it useful ?

  • A headless browser is a great tool for automated testing and server environments where you don’t need a visible UI shell.
  • And again its not a completely new technology, since there are other big players in this area such as
    • PhantomJS
    • HTMLUnitDriver

So when is Chrome Headless available ?

  • Chrome Headless is supported from Chrome 59.x and above.
  • The current stable version for Windows 10 is Chrome 60.x
  • ChromeDriver v2.30 and above supports headless mode

What changes should I make in my Existing Selenium test ?

https://gist.github.com/executeautomation/b7c7da64027b9d2d011ec80006f46e3b Here is the complete video of the above discussion   Thanks for reading the post and watching the video!!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

15 Replies to “Running Chrome in headless mode with Selenium C#”

  1. Thanks a lot for the post. I tried to follow the same steps, but didn’t work out. I used :
    Chrome Version 59.0.3071.115 (Official Build) (64-bit)
    Windows 10 64 bit
    package id=”Selenium.WebDriver.ChromeDriver” version=”2.31.0″ targetFramework=”net45″ /> this is the same ChromeDriver that you guys mentioned in you video.

    the problem I have is that it does not recognize the IWebDriver and it keeps giving me missing-reference error. I really appreciate you help.

    1. Did you added Selenium reference in your project ?

      Also make sure you have installed Chrome latest version which is 60.x now

      Thanks,
      Karthik KK

  2. Have you successfully used the remote debugging port option with selenium C#? I have tried using this option to allow me to debug some issues I’m having with moving my automated tests from PhantomJS to headless Chrome but I get a timeout error when using the remote debugging port as an option

  3. Hi, I need to validate URL of a page launched in headless chrome browser for my automation validation. please help me how to code that.

  4. Hello Karthik , thanks for article, very usefull.

    I would like to ask you. I have an NetCore.Web 2.0 application and would like to know if it is compatible with CrhomeDriver. (I’m developing a webservice do read a url and catch some info from there, that page are using angularjs).

  5. Hi Karthik,

    Do u have a detailed Udemy Series or something similar for CRM API headless automation ??

  6. Hi karthi.. Good one..
    I have issue on chrome headless.. Ho lw we can download files in chrome headless mode.. I’m using c#.., I saw that we need to change the behavior of chrome.. I tried.. But no luck.. Can u please help me..

    1. var chromeOptions = new ChromeOptions();
      chromeOptions.AddUserProfilePreference(“download.default_directory”, downloadSaveFolder);
      chromeOptions.AddUserProfilePreference(“disable-popup-blocking”, “true”);
      chromeOptions.AddArgument(“–headless”);

      ChromeDriver bot = new ChromeDriver(DriverFolder, chromeOptions);

      Dictionary param = new Dictionary();
      param.Add(“behavior”, “allow”);
      param.Add(“downloadPath”, pasta);
      bot.ExecuteChromeCommand(“Page.setDownloadBehavior”, param);

  7. var chromeOptions = new ChromeOptions();
    chromeOptions.AddUserProfilePreference(“download.default_directory”, downloadSaveFolder);
    chromeOptions.AddUserProfilePreference(“disable-popup-blocking”, “true”);
    chromeOptions.AddArgument(“–headless”);

    ChromeDriver bot = new ChromeDriver(DriverFolder, chromeOptions);

    Dictionary param = new Dictionary();
    param.Add(“behavior”, “allow”);
    param.Add(“downloadPath”, pasta);
    bot.ExecuteChromeCommand(“Page.setDownloadBehavior”, param);

  8. this is my chrome options.

    var options = new ChromeOptions();
    options.AddExcludedArgument(“enable-automation”);
    options.AddArguments(new List
    { “–headless” });

    when i run this ,i occur this error:
    no such element: Unable to locate element: {“method”:”css selector”,”selector”:”[class=’landing-candidate__mobile’] img”}
    (Session info: headless chrome=75.0.3770.142)

    how to solve this problem??
    thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *