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'