1

I need to open the maximized page, but selenium does not work. It just opens the page usually.

from selenium.webdriver.chrome.options import Options    
options = Options()
options.add_argument("--start-maximized")
driver = webdriver.Chrome(executable_path=r'/Users/chromedriver', options=options)
Prophet
  • 32,350
  • 22
  • 54
  • 79
Mahdi
  • 967
  • 4
  • 18
  • 34

5 Answers5

2

Per this post How to maximize chrome browser in default when using selenium in python you can try chrome_options.add_argument("--start-maximized") and depending on your version of chromedriver, it's worth reading through this post: How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

driver.maximize_window() also seems to be an option to try.

Wunderbread
  • 898
  • 2
  • 14
  • 34
  • driver.maximize_window() is working, but how to maximize the window using chrome options? – Mahdi Oct 16 '22 at 05:15
1

Do you mean --start-fullscreen?

craigb
  • 1,081
  • 1
  • 9
1

You should try this options.add_argument("window-size=1920,1080")

Tu Nguyen
  • 31
  • 1
  • 4
0

The -- shouldn't be there.
The correct syntax is:

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

options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')

driver = webdriver.Chrome(options=options, service=webdriver_service)
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Actually, I don't use the selenium service because of its requirement to check the latest version of the chromedriver every time. Removing -- does not work. – Mahdi Oct 17 '22 at 00:07
  • You don't have to use service. I just pasted the code that is 100% working. Your problem is redundant '--' as I mentioned. – Prophet Oct 17 '22 at 18:34
0

And in C# it will be Driver.Manage().Window.Maximize();.

manymanymore
  • 2,251
  • 3
  • 26
  • 48