0

I am having an hard time figuring out how to launch Selenium Webdriver for Chrome in incognito mode.

I understand I need to pass the --incognito parameter to chromedriver, but how do I do that when creating the driver instance?

This is how I am currently instantiating my driver object:

require("chromedriver");
const webdriver = require("selenium-webdriver");
const driver = new webdriver.Builder().forBrowser("chrome").build();
1

2 Answers 2

3

You have to add --incognito to your ChromeOptions or DesiredCapabilities.

I don't use node.js, but judging by the README.md from the Selenium GitHub it should look like this:

var options = new chrome.Options();
options.addArguments("--incognito");
const driver = new webdriver.Builder().forBrowser("chrome").setChromeOptions(options).build();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, your answer has been useful in directing me to the actual Node.js solution
0

This gist by the github user anandsunderraman helped me solving the problem in Node.js:

// import the selenium web driver
var webdriver = require('selenium-webdriver');

// create chrome capabilities
var chromeCapabilities = webdriver.Capabilities.chrome();

// add the desired options
var chromeOptions = {'args': ['--test-type', '--incognito']};
chromeCapabilities.set('chromeOptions', chromeOptions);

var driver = new webdriver.Builder().withCapabilities(chromeCapabilities).build();

2 Comments

FYI, for anyone trying to use 4.0.0-alpha.5 of Selenium Web Driver, the above does not work. You will need to use version 3.6.0.
If you're using selenium 4, use goo:chromeOptions instead of chromeOptions to set the capabilities. chromeCapabilities.set("goog:chromeOptions", chromeOptions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.