I am writing a script by using selenium. My problem is when the chrome has been automatically updated, my script is not working. So, my solution is learning the web chrome version (not driver) at the beginning and run the related chrome driver. So on my desktop I will keep all versions and run the correct one. But I could not find a solution to get the version of chrome. I will kindly appreciate the helps! Thanks in advance!
Asked
Active
Viewed 2,543 times
3
-
Maybe call 'google-chrome --version' from python? [call like this](https://stackoverflow.com/questions/89228/calling-an-external-command-from-python) – shimo Jan 10 '20 at 12:29
-
I think it will be solution but anyway I could not find what exactly should I write – Oguzhan Rmre Akdag Jan 10 '20 at 12:51
-
If you are on windows, try this (https://stackoverflow.com/questions/50880917/how-to-get-chrome-version-using-command-prompt-in-windows). Worked for me. – Satish Jan 10 '20 at 12:58
-
I should get it via Python, using cmd is a manual step for me. Thank you – Oguzhan Rmre Akdag Jan 10 '20 at 13:03
-
See my answer below – Satish Jan 10 '20 at 13:13
1 Answers
8
Try this.
import subprocess
output = subprocess.check_output(
r'wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value',
shell=True
)
print(output.decode('utf-8').strip())
output
Version=79.0.3945.117

Satish
- 1,976
- 1
- 15
- 19
-
I had missed "print(output.decode('utf-8').strip())" . You are a hero, thanks a lot:) – Oguzhan Rmre Akdag Jan 10 '20 at 13:19
-
-
thanks a lot man ;XX i wrote code: cmd_args = [rf'wmic datafile where name="{chrome_path}".format() get Version /value'] subprocess.Popen(cmd_args, cwd='C:\\Windows\\SysWOW64\\wbem') but didn't work. and for you worked good. – ali reza Jun 01 '23 at 02:16