4

For Chrome I have this code :

    List<String> capabilityValue = new List<string>();
    capabilityValue.Add("--start-maximized");
    capabilities = DesiredCapabilities.Chrome();
    capabilities.SetCapability("chrome.switches", capabilityValue);
    capabilities.Platform = new Platform(platform);
    WebDriver driver = new WebDriver ("www.google.com", capabilities); 

I try to replace chrome.switches with firefox.switches. For Mozilla Firefox this doesn't work.

Can anyone know how can I open site as maximized?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Cr123
  • 93
  • 1
  • 2
  • 7
  • 2
    I don't understand why some guys gave negative votes to this, the accepted answer has 4+ and the post 2k views already. So the replacement with `firefox.switches` was naive but the question utility remains. – Leo Gallucci Jan 17 '14 at 13:23

2 Answers2

11

For Firefox use -

driver.Manage().Window.Maximize();

You can check this link for more details - How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

Community
  • 1
  • 1
Hari Reddy
  • 3,808
  • 4
  • 33
  • 42
  • Doesn't work for me .I receive an error message : Unexpected error . – Cr123 May 18 '12 at 08:50
  • @Cr123 upgrade your webdriver to the latest version. – Aleh Douhi May 18 '12 at 20:45
  • This actually works with Chrome too as of now. If you get `Unexpected error` upgrade selenium-webdriver to latest. FYI the javascript syntax for this is `browser.manage().window().maximize();` – Leo Gallucci Jan 17 '14 at 13:20
0

Firefox doesn't have a command line parameter to open the window maximized but you could specify the window size explicitly instead. E.g. this should set window size to 800x600:

capabilityValue.Add("-width");
capabilityValue.Add("800");
capabilityValue.Add("-height");
capabilityValue.Add("600");
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • I Try to write so : capabilityValue.Add("1024"); capabilities.SetCapability("-width", capabilityValue); capabilityValue.Add("768"); capabilities.SetCapability("-height", capabilityValue); capabilities.Platform = new Platform(platform); but doesn't work.Can you write me all the code? – Cr123 May 18 '12 at 08:47
  • it works If I put driver.Manage().Window.Size = new System.Drawing.Size(1152,864).But how to get max width and max height? – Cr123 May 18 '12 at 09:16