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());
}
}
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());
}
}
We will use IE Driver Capabilities to open IE in Private 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());
}
}