Chrome in Incognito/Private mode

We will use Chrome Drivers Capabilities & ChromeOptions to open Chrome browser in incognito mode. To be precise, we have to use argument –incognito for ChromeOption.


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PrivateBrowsing {
    public static void main(String args[]){
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--incognito");
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        System.setProperty("webdriver.chrome.driver","D:\\PATH\\chromedriver.exe");
        WebDriver driver = new ChromeDriver(capabilities);
        driver.get("https://chercher.tech");
        System.out.println(driver.getTitle());
    }
}		

Firefox in Incognito/Private mode

We will use Firefox Profile to open Firefox in private mode. To be precise, we will set browser.private.browsing.autostart in firefox profile preference.


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PrivateBrowsing {
    public static void main(String args[]){
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("browser.private.browsing.autostart",true);
        WebDriver driver = new FirefoxDriver(firefoxProfile);
        driver.get("https://chercher.tech");
        System.out.println(driver.getTitle());
    }
}		

Internet Explorer in Incognito/Private mode

We will use IE Driver Capabilities to open IE in InPrivate mode. To be precise we will use FORCE_CREATE_PROCESS capability along with IE_SWITCHES to which parameter would be -private


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PrivateBrowsing {
    public static void main(String args[]){
         DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
        capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
        System.setProperty("webdriver.ie.driver","D:\\PATH\\IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver(capabilities);
        driver.get("https://chercher.tech");
        System.out.println(driver.getTitle());
    }
}		

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Protractor Training

new tutorial I am starting new Protractor training batch on Weekends. Course starts from 08-june-2019 [10am IST to 1 pm IST] based on online for 6 days, and course fee is INR 10, 000.

Interested people can confirm the seat by calling to +91 8971673487 or whatsapp to +91 9003381224

Find the course content : View Content