0

I try to set bowser size to a certain dimensions using:

browser = webdriver.Chrome()
browser.set_window_position(100, 100)
browser.set_window_size(1024, 768)

but it seems webdriver ignores Y parameter - window is correctly shifted 100 points from the left, but the 100 points from the top are ignored. The most annoying is that Y dimension is ignored too - window height is set to 2035 points (4K monitor height minus taskbar) (Linux x86_64, KF5, Python 3.9.1, Selenium 3.141.0). I've seen solution with just maximizing the window, but having window 6 time larger than necessary seems no OK. Currently I create virtual desktop of appropriate size and then maximise window on it, but I don't think its sustainable solution.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
JanisE
  • 37
  • 1
  • 8
  • your code works fine , how do you validate that the y is ignored ? – PDHide Mar 07 '21 at 20:27
  • :) By just running the code and observing salami-like window stretching from the very top of the screen till the bottom of it. The only reason i see are some defaults in the Selenium module - when I applied the solution, evrth works fine. – JanisE Mar 09 '21 at 06:19

1 Answers1

0

Found a solution:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("window-size=1600,900")
options.add_argument("window-position=2230,0")
browser = webdriver.Chrome(options=options)

related info found here: How to set window size in Selenium Chrome Python

JanisE
  • 37
  • 1
  • 8