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

前端 未结 28 2327
悲&欢浪女
悲&欢浪女 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:34

    For me, none of the solutions above worked when working with Selenium Web Driver C# + Chrome:

    • window.resizeTo(1024, 768); - I want to use the whole screen
    • --start-maximized - it is ignored
    • driver.manage().window().maximize(); - does not work because it requires some extension and I am not allowed to use Chrome extensions

    I managed to get it working using InputSimulator:

    var inputSim = new InputSimulator();
    // WinKey + UP = Maximize focused window
    inputSim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.UP);
    

提交回复
热议问题