1

I am writing a script in Selenium WebDriver using C#. I want to run this script in the background or minimize mode. I don't want to display the browser to the user. I tried the Chrome Options class and its properties to accomplish the task but unable to do that.

What could be the best approach of running the selenium script in the background or minimize mode in Selenium WebDriver using C#?

Ashish Sharma
  • 131
  • 1
  • 5
  • 19

1 Answers1

1

To minimize:

driver.Manage().Window.Size = new Size(-2000, 0);

To background use a headless webdriver:

WebDriver htmlUnitDriver = new HtmlUnitDriver();

Or for Headless Chrome, see here, it's not a simple solution though.

Best approach: depends on your case. For testing a web app use Chrome minimized. For scraping, use a headless browser.

Moshisho
  • 2,781
  • 1
  • 23
  • 39