Open Internet Explorer in Private Mode with Selenium

1.8k Views Asked by At

So I've been trying to open IE in Private using selenium (C#), this is the closest i've come so far:

        InternetExplorerOptions op = new InternetExplorerOptions();
        op.PageLoadStrategy = PageLoadStrategy.Normal;
        op.IgnoreZoomLevel = true;
        op.InitialBrowserUrl = "https://entry.wgrintra.net/schadenwv/servlet/main";
        op.ForceCreateProcessApi = true;
        op.BrowserCommandLineArguments = "-private";
        IWebDriver driver = new InternetExplorerDriver(op);

The problem here is, after 60 seconds of opening the browser (correctly in private) the driver times out (last step doesn't finish).

I've looked around a lot, most is just using Capabilities which are not useful anymore.

(I had to add a value to the registry to be able to forcecreate the process api)

1

There are 1 best solutions below

2
On

Try to refer code example below and make a test with it on your side may help to solve your issue.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 * Created by Amol Chavan on 9/19/2016.
 */
public class PrivateBrowsing {

    public static void main(String args[]){
        createInstance();
    }

    public static WebDriver createInstance(){
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
        capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
        System.setProperty("webdriver.ie.driver","C:\\Grid\\IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver(capabilities);
        driver.get("http://www.google.com");
        return driver;
    }
}

Reference:

How to Open Internet Explorer Browser in Incognito / Private mode using Selenium / WebDriver ?