How to open incognito/private window with Selenium WD for different browser types?

后端 未结 9 897
感情败类
感情败类 2020-12-05 08:18

I want to test my test cases in private window or incognito window.

How to do the same in various browsers:

相关标签:
9条回答
  • 2020-12-05 09:15

    In chrome you can try using -incognito command line switch in options, not sure if there will be a problem with automation extension but worth a try.

    ChromeOptions options = new ChromeOptions();
    options.addArguments("incognito");
    

    For FireFox, a special flag in the profile can be used for the purpose

    FirefoxProfile firefoxProfile = new FirefoxProfile();    
    firefoxProfile.setPreference("browser.private.browsing.autostart",true);
    

    For IE

    setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
    
    0 讨论(0)
  • 2020-12-05 09:16

    I was able to run remote IE in private mode only after following updates:

    InternetExplorerOptions options = new InternetExplorerOptions()
                        .ignoreZoomSettings()
                        .useCreateProcessApiToLaunchIe()
                        .addCommandSwitches("-private");
    
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
                capabilities.setCapability("se:ieOptions", options);
    return new RemoteWebDriver(url, capabilities);
    

    All of above didn't work for RemoteWebDriver.

    0 讨论(0)
  • 2020-12-05 09:17
    public class gettext {
      static WebDriver driver= null;
    
      public static void main(String args[]) throws InterruptedException {
    
        //for private window
    
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeOptions option = new ChromeOptions();
        option.addArguments("incognito");
        capabilities.setCapability(ChromeOptions.CAPABILITY,option);
        System.setProperty("webdriver.chrome.driver", "D:\\Tools\\chromedriver.exe");       
        driver= new ChromeDriver(capabilities);
    
        String url = "https://www.google.com/";
        driver.manage().window().maximize();
        driver.get(url);
        driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
        gettextdata();
      } 
    }
    
    0 讨论(0)
提交回复
热议问题