4

I'm trying to write in some defensive code to prevent someone from executing a script should they have an older version of geckodriver installed. I cannot for the life of me seem to get the geckodriver version from the webdriver object.

The closest I found is driver.capabilities which contains the firefox browser version, but not the geckodriver version.

from selenium import webdriver
driver = webdriver.Firefox()
pprint(driver.capabilities)

output:

{'acceptInsecureCerts': True,
 'browserName': 'firefox',
 'browserVersion': '60.0',
 'moz:accessibilityChecks': False,
 'moz:headless': False,
 'moz:processID': 18584,
 'moz:profile': '/var/folders/qz/0dsxssjd1133p_y44qbdszn00000gp/T/rust_mozprofile.GsKFWZ9kFgMT',
 'moz:useNonSpecCompliantPointerOrigin': False,
 'moz:webdriverClick': True,
 'pageLoadStrategy': 'normal',
 'platformName': 'darwin',
 'platformVersion': '17.5.0',
 'rotatable': False,
 'timeouts': {'implicit': 0, 'pageLoad': 300000, 'script': 30000}}

Is it possible the browser version and geckodriver versions are linked directly? if not, how can I check the geckodriver version from within python?

Marcel Wilson
  • 3,842
  • 1
  • 26
  • 55

2 Answers2

5

There is no method in the python bindings to get the geckodriver version, you will have to implement it yourself, my first option would be subprocess

# Mind the encoding, it must match your system's
output = subprocess.run(['geckodriver', '-V'], stdout=subprocess.PIPE, encoding='utf-8')
version = output.stdout.splitlines()[0].split()[-1]
Dalvenjia
  • 1,953
  • 1
  • 12
  • 16
  • My guess on the lack of such method is because it's not specified in W3C's webdriver specification hence there's no method implemented on the geckodriver side to query the version via the JSON Wire protocol – Dalvenjia May 15 '18 at 21:53
  • 1
    the version appears in the log file `geckodriver INFO geckodriver 0.19.1`, maybe there is something to find from here ? – PRMoureu May 15 '18 at 22:16
4

It appears that moz:geckodriverVersion has been added to the capabilities sometime late 2018.

driverversion = driver.capabilities['moz:geckodriverVersion']
browserversion = driver.capabilities['browserVersion']
Marcel Wilson
  • 3,842
  • 1
  • 26
  • 55