Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the geckodriver version from python selenium firefox webdriver?

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?

like image 384
Marcel Wilson Avatar asked Oct 18 '25 07:10

Marcel Wilson


1 Answers

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]
like image 65
Dalvenjia Avatar answered Oct 19 '25 21:10

Dalvenjia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!