Selenium WebDriver - Chrome - C# - Unable to launch selenium browser in Incognito Mode as a maximised browser

10,137

Solution 1

Try this code:

ChromeOptions options = new ChromeOptions();
options.AddArguments("--incognito");
IWebDriver driver = new ChromeDriver("C://",options);

It works for me

Solution 2

Could do something like this:

desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(@"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);

webDriver.Manage().Window.Maximize();
 break; 

It will need to be after the webDriver opens up, but it will maximize the window for you.

Try this instead, I have tested and should be fine

  var caps = DesiredCapabilities.Chrome();
            var options = new ChromeOptions();

            options.AddArgument(@"--incognito");
            options.AddArgument(@"--start-maximized");
            caps.SetCapability(ChromeOptions.Capability, options);



            var webdriver = new ChromeDriver(options);
            webdriver.Navigate().GoToUrl("http://yourURL.com");
            webdriver.Manage().Window.Maximize();
Share:
10,137
Timothy Rajan
Author by

Timothy Rajan

Updated on June 17, 2022

Comments

  • Timothy Rajan
    Timothy Rajan almost 2 years

    I have a Selenium suite which has 150 test cases. The test has to run in Incognito mode in Chrome Browser.

    I am able to launch the browser in incognito Mode. But the issue is the browser is not getting maximized ( say for 10 test cases and for remaining 140 test cases the browser launches in maximized mode) , though there is a code to maximize the browser.

    As a result of this, some of the test fails ( All 10 test ).

    Below is my code

                    desiredCapabilities = DesiredCapabilities.Chrome();
                    var options = new ChromeOptions();
                    options.AddArgument(@"--incognito");
                    options.AddArgument("--start-maximized");
                    desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
                    webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
                    break;
    

    Is there a way to ensure that the browser always (100%) launches in maximised mode.

    The click operation fails when the browser is not maximised.

    System.InvalidOperationException: unknown error: Element is not clickable at point (886, 466). Other element would receive the click:

    For this reason, I want to run in maximised mode. In maximised mode, I am not getting this error. Please help .

    Thanks