Running chrome browser in inconginto Mode in Selenium

We can run Chrome browser Incognito mode with Selenium webdriver. Incognito mode is a safe mode of opening a browser. This can be done with the help of the DesiredCapabilities and ChromeOptions class.

We shall create an object of the ChromeOptions class and apply addArguments method on it. Then pass −−incognito as a parameter to that method. We shall then create an object of the DesiredCapabilities class.

We shall apply setCapability method on the object of the DesiredCapabilities class and pass the ChromeOptions.CAPABILITY and the object of ChromeOptions class as parameters to that method.

Finally, this browser chrome profile shall be fed to the webdriver object.


ChromeOptions o= new ChromeOptions();
DesiredCapabilities c =;
c.setCapability(ChromeOptions.CAPABILITY, o);
WebDriver driver = new ChromeDriver(o);


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BrwIncognt{
   public static void main(String[] args) {
      // configure options parameter to Chrome driver
      ChromeOptions o= new ChromeOptions();
      // add Incognito parameter
      // DesiredCapabilities object
      DesiredCapabilities c =;
      //set capability to browser
      c.setCapability(ChromeOptions.CAPABILITY, o);
      WebDriver driver = new ChromeDriver(o);
      driver.get(" ");


Updated on: 02-Feb-2021

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started