0

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver

I am using the below code:

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--incognito");
        DesiredCapabilities capabilities =  DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(capabilities);
        driver.manage().window().maximize();

But in the last line code I am getting error as Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: No current window

Pulkit Agrawal
  • 143
  • 1
  • 11

1 Answers1

1

To maximize the Chrome Browser in incognito mode you need to use the ChromeOptions class as follows:

ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281