How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

前端 未结 28 2320
悲&欢浪女
悲&欢浪女 2020-11-29 18:20

Is there any way to maximize the browser window using WebDriver (Selenium 2) with C#?

28条回答
  •  无人及你
    2020-11-29 18:29

    The below line of code would maximize IE, Chrome and Mozilla

    driver.manage().window().maximize();
    

    The above line of code and other workarounds mentioned in the post did not work for NodeWebKit browser, so as a workaround i had to use native C# code as mentioned below:

    public static void MaximiseNWKBrowser(IWebDriver d)
            {
                var body = UICommon.GetElement(By.TagName("body"), d);
                body.Click();
                string alt = "%";
                string space = " ";
                string down = "{DOWN}";
                string enter = "{ENTER}";
                SendKeys.SendWait(alt + space);
                for(var i = 1; i <= 6; i++)
                {
                    SendKeys.SendWait(down);
                }
                SendKeys.SendWait(enter);            
            }
    

    So this workaround basically uses "ALT+SPACE" to bring up the browser action menu to select "MAXIMIZE" from the options and presses "ENTER"

提交回复
热议问题