4

I would like to move my browser window to the left or right side of the screen. Manually I would press[WINDOW] + [LeftArrow] (or [RightArrow]) to achieve this.

I've read this one but it's for Java (see comments) but I can't find a way to press the windows key when using C#.

My best option seems to be:

driver.Manage().Window.Position = new Point(x-coord, y-coord);
driver.Manage().Window.Size = new Size(myWidth,myHeight); 

but seems to be a bit fiddly, and I'm sure there is a better way.

I have also tried:

Actions action = new Actions(driver);
action.SendKeys(Keys.   )

Then Keys doesn't have the windows key...

Community
  • 1
  • 1
Pierre
  • 559
  • 9
  • 21

2 Answers2

4

If you'd like to go for they SendKeys approach, sending key combinations that include the Windows logo key is not straightforward. The equivalent for the Windows logo key alone would be Strg + Esc. While that can be simulated, Strg + Esc + Left would just open the start menu (or whatever they call it now in Windows 10), and then send another left arrow.

But here there is a solution.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77
  • Thank you! I have not tried yet, but seems just like the thing i wanted! And apparently I need to work on my google skills since I did not find it myself... – Pierre Jul 31 '16 at 06:43
0

dllatikay's answer is very helpful for understanding how things work. I will just add a working example - how to maximize browser window when using Selenium:

 // Install-Package InputSimulator in package manager
 var inputSim = new InputSimulator();
 // WinKey + Up maximizes current focused window
 inputSim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.UP);
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164