I am trying to write a selenium script that can work without needing any updates. I'd like to be able to run the program, and determine which Google Chrome version is currently installed on OS (it can be either Windows or Linux), and then install the compatible ChromeDriver from there.
I already tried this to simply attempt printing the value:
public static void chromeVersion() throws IOException {
String installPath = "";
Process userProcess;
BufferedReader usersReader;
if(SystemUtils.IS_OS_WINDOWS) {
installPath = "C:/Program Files/Google/Chrome/Application/chrome.exe";
userProcess = Runtime.getRuntime().exec(installPath + " --version");
usersReader = new BufferedReader(new InputStreamReader(userProcess.getInputStream()));
String p;
while ((p = usersReader.readLine()) != null){
System.out.println(p);
}
}
}
But it prints a runtime error saying that the path cannot be found. Even if the path was correct, I doubt that this is the best solution since the path technically could vary even from one Windows computer to another.
What else can I do to accomplish this task?
EDIT: after further research, it seems that this may not be possible in Java? Thoughts?
EDIT: Hulk in the comments pointed out that I can do this:
public static void chromeVersion() throws IOException {
String installPath = "";
Process userProcess;
BufferedReader usersReader;
if(SystemUtils.IS_OS_WINDOWS) {
installPath = "reg query 'HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon' /v version";
;
userProcess = Runtime.getRuntime().exec(installPath);
usersReader = new BufferedReader(new InputStreamReader(userProcess.getInputStream()));
String p;
while ((p = usersReader.readLine()) != null){
System.out.println(p);
}
}
}
This however does not print anything, but if I run reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
from CMD then I get this:
HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon
version REG_SZ 93.0.4577.82