-1

The goal is to automate the web browser to start with a specific window size.

I've tried two implementations. Implementation with chromedriver does the job, while the implementation with geckodriver fails. To be precise, both implementations start the browser, but only one of them sets the specified window size. I would like to understand why. Am I using it wrong or something else is at hand?

Implementation no. 1, with geckodriver fails to set the window size:

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

geckodriver_path = Service('/usr/bin/geckodriver')

firefox_options = Options()
firefox_options.add_argument('--window-size=800,800')
driver = webdriver.Firefox(service = geckodriver_path, options = firefox_options)

driver.get("http://www.wikipedia.org")
print(driver.get_window_size())

Implementation no. 2, with chromedriver sets the window size correctly:

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

chromedriver_path = Service('/usr/bin/chromedriver')

chrome_options = Options()
chrome_options.add_argument('--window-size=800,800')
driver = webdriver.Chrome(service = chromedriver_path, options = chrome_options)

driver.get("http://www.wikipedia.org")
print(driver.get_window_size())

Additional info:

[boris@E7490-DELL ~]$ python -V
Python 3.10.5
[boris@E7490-DELL ~]$ chromedriver --version
ChromeDriver 103.0.5060.53 (a1711811edd74ff1cf2150f36ffa3b0dae40b17f-refs/branch-heads/5060@{#853})
[boris@E7490-DELL ~]$ geckodriver -V
geckodriver 0.31.0 (b617178ef491 2022-04-06 11:57 +0000)
[boris@E7490-DELL ~]$ google-chrome --version
Google Chrome 103.0.5060.53 
[boris@E7490-DELL ~]$ firefox -v
Mozilla Firefox 101.0.1

[boris@E7490-DELL ~]$ python
Python 3.10.5 (main, Jun  9 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> selenium.__version__
'4.1.0'
Boris L.
  • 936
  • 2
  • 12
  • 28
  • This looks like a duplicate https://stackoverflow.com/questions/15397483/how-do-i-set-browser-width-and-height-in-selenium-webdriver – dosas Jun 28 '22 at 10:27
  • Thanks @dosas, I haven't seen this one before, but I did find an answer in there – Boris L. Jun 28 '22 at 11:37

1 Answers1

-1

Firefox requires separation of the with and height dimensions.

firefox_options.add_argument('--width=800')
firefox_options.add_argument('--height=800')
Boris L.
  • 936
  • 2
  • 12
  • 28