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());
    }
}		

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : We have closed registration for training

Please do email to chercher.tech@gmail.com for any queries

If you already registered then please do check your email for the Webex link for the training starting from 15th Nov 2018
 
Join My Facebook Group
Join Group