close

How to set window size in Selenium Chrome Python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to set window size in Selenium Chrome Python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to set window size in Selenium Chrome Python?

  1. How to set window size in Selenium Chrome Python?

    So I finally figured out what the problem is: Running Windows task scheduler with option 'run whether user is logged on or not' only opens a small browser (1024×768) that CANNOT be resized, even with all the great suggestions being offered here.

  2. set window size in Selenium Chrome Python

    So I finally figured out what the problem is: Running Windows task scheduler with option 'run whether user is logged on or not' only opens a small browser (1024×768) that CANNOT be resized, even with all the great suggestions being offered here.

Method 1

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

Method 2

So I finally figured out what the problem is: Running Windows task scheduler with option ‘run whether user is logged on or not’ only opens a small browser (1024×768) that CANNOT be resized, even with all the great suggestions being offered here.

See the same issue resolved here: screen resolution in mode “Run whether user is logged on or not”, in windows task scheduler

So the less than ideal workaround is to only run when user is logged on.

Thanks for all your help!

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read