0

I am not able to maximize the headless chrome window size to full size that is available. I am trying the following but still the window size remains the default(800px,600px). Kindly help me to set the size to full screen.

MY code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument("--disable-gpu")
options.add_argument('--start-maximized')
driver = webdriver.Chrome(DRIVER_PATH, options=options)
driver.maximize_window()

driver.get(SOME_URL)
size = driver.get_window_size()
print("Window size: width = {}px, height = {}px".format(size["width"], size["height"]))

I get the output :

enter image description here

ameesha gupta
  • 101
  • 11
  • Have you tried `driver.set_window_size(1920, 1080)` ? – Akzy Mar 17 '23 at 07:38
  • @Akzy No this doesn't work and gives me error. Also I don't want to give a hardcoded value to window and rather it should open to maximized size. – ameesha gupta Mar 17 '23 at 08:06
  • What `error` are you getting ? You may use this one too if you do not want hardcode `driver.execute_script("window.maximize();")` – Akzy Mar 17 '23 at 08:36
  • @Akzy tried your driver.execute_script("window.maximize();") and got the error--- selenium.common.exceptions.JavascriptException: Message: javascript error: window.maximize is not a function – ameesha gupta Mar 17 '23 at 08:42
  • 2
    https://stackoverflow.com/a/44827872/7598774 - Check this. This should answer your query. – Shawn Mar 17 '23 at 09:49
  • @Shawn Thanks for sharing this url. I'm commenting the same in answer to this question. – ameesha gupta Mar 21 '23 at 08:20

1 Answers1

1

As mentioned by @shawn in comments above this has answer to this question and the limitation of setting window size in headless chrome.

ameesha gupta
  • 101
  • 11