locked
How can I start Edge in Private Mode with Selenium in Java? RRS feed

  • Question

  • I would like to start Edge in Private Mode with Selenium in Java, I would like to know which capabilities do I need to set.

    Thanks.

    Friday, January 31, 2020 7:18 AM

All replies

  • Hi beasanca,

    Below is the Selenium JAVA sample code to launch Edge browser in private mode.

    package selenium_test;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.edge.*;
    import org.openqa.selenium.WebElement;
    public class new_java_class {
    
            public static void main(String[] args) {
                     
                      System.setProperty("webdriver.edge.driver","D:\\selenium web drivers\\MicrosoftWebDriver.exe"); 
                      EdgeOptions op=new EdgeOptions();
                      op.setCapability("InPrivate", true);
                   	  WebDriver browser = new EdgeDriver(op);
                   
                   browser.get("http://example/login.com");
                   
                   WebElement username = browser.findElement(By.name("uname"));		
                   username.sendKeys("test_user");
                   
                   WebElement password = browser.findElement(By.name("psw"));		
                   password.sendKeys("abcd@1234");
                   
                   WebElement btn = browser.findElement(By.name("signIn"));		
                   btn.click();
                   
            }
    
    }

    Regards,

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 4, 2020 7:07 AM
  • Hi Deepak, 

    Can you say for chromium how to open in Private Mode with Selenium in Java, and also with headless mode.

    Thank you.


    Friday, May 22, 2020 9:55 AM