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

后端 未结 9 902
感情败类
感情败类 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: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();
      } 
    }
    

提交回复
热议问题