A bit unclear why and exactly where you are stuck. Possibly the extra .
as in height = {}px.
is creating the chaos. Perhaps along with -headless
argument I am able to set/retrieve the Chrome browser Window Size as follows:
-
Code Block:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("--headless") options.add_argument("window-size=1400,600") driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe', service_args=["--log-path=./Logs/DubiousDan.log"]) driver.get("http://google.com/") print ("Headless Chrome Initialized") print(driver.get_window_size()) driver.set_window_size(1920, 1080) size = driver.get_window_size() print("Window size: width = {}px, height = {}px".format(size["width"], size["height"])) driver.quit()
-
Console Output:
Headless Chrome Initialized {'width': 1400, 'height': 600} Window size: width = 1920px, height = 1080px
tl; dr
You find a couple of relevant discussion on window size in:
- python: Selenium Firefox headless returns different results
- java: Not able to maximize Chrome Window in headless mode