2

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

3 Answers 3

9

Try this code:

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

It works for me

Sign up to request clarification or add additional context in comments.

Comments

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();

2 Comments

I tried this but resulted in exception. Thanks for your help.
See the edits. If still exception please post exception so we can locate the issue
0

An alternative would be to set the initial size:

options.AddArgument("--window-size=1024,768");

You could also set some extreme values. The window should then have the size of the screen since the OS limits it (at least on Windows) :

options.AddArgument("--window-size=32000,32000");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.