javaseleniumgoogle-chromeselenium-webdriverwebdrivermanager-java

WebDriverManager is pulling chrome browser version from a default path regardless of settings


I've tried everything I can think of to get WebDriverManager to detect the correct version of the chrome browser that I can think of, nothing works. I want to detect the browser driver version from the chrome.exe located at C:\Program Files\Google\Chrome Beta\Application. However, no matter what I do it runs the following command to detect the version:

io.github.bonigarcia.wdm.versions.Shell - Running command on the shell: [cmd.exe, /C, wmic, datafile, where, name="%PROGRAMFILES(X86):\=\\%\\Google\\Chrome\\Application\\chrome.exe", get, Version, /value]

I have tried so far:

For all the below:

sBrowserBinaryLocation = "C:\Program Files\Google\Chrome Beta\Application"; 

setting

options.setBinary(sBrowserBinaryLocation);
WebDriverManager.chromedriver().clearDriverCache().setup();

Setting:

options.setBinary(sBrowserBinaryLocation);
WebDriverManager.chromedriver().clearDriverCache().arch64().setup();

Setting:

options.setBinary(sBrowserBinaryLocation);
WebDriverManager.chromedriver().clearDriverCache().browserVersionDetectionCommand(sBrowserBinaryLocation + " --version").arch64().setup();

Every one of those produced the same

io.github.bonigarcia.wdm.versions.Shell - Running command on the shell: [cmd.exe, /C, wmic, datafile, where, name="%PROGRAMFILES(X86):\=\\%\\Google\\Chrome\\Application\\chrome.exe", get, Version, /value]

Which picked up the non-beta version 99. How do I tell WebDriverManager to use "C:\Program Files\Google\Chrome Beta\Application" rather than "C:\Program Files(x86)\Google\Chrome\Application"?


Solution

  • Although it is tricky, it can be done using the WebDriverManager method browserVersionDetectionCommand(). Supposing that Chrome Beta is in this path:

    C:\Program Files\Google\Chrome Beta\Application\chrome.exe
    

    ... we need to run the following command in the shell:

    cmd.exe /C wmic datafile where name="%PROGRAMFILES:\=\\%\\Google\\Chrome Beta\\Application\\chrome.exe" get Version /value
    

    The problem is that, when running this command in Java, the blank space (in "Chrome Beta" folder) makes this command to be interpreted incorretly. The solution is to find the Windows path name using the ~ sintax. You can discover these names by running dir /X in the Windows shell (e.g, C:\Program Files becomes C:\PROGRA~1).

    You can see a test using this feature here. The traces of this test are as follows:

    2022-03-23 13:35:00 [main] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(65) -- Running command on the shell: [cmd.exe, /C, wmic, datafile, where, name="C:\\PROGRA~1\\GOOGLE\\CHROME~1\\APPLIC~1\\CHROME.EXE", get, Version, /value]
    2022-03-23 13:35:00 [main] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(69) -- Result: Version=100.0.4896.46
    2022-03-23 13:35:00 [main] DEBUG i.g.b.wdm.versions.VersionDetector.getDriverVersionFromRepository(127) -- Latest version of chromedriver according to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_100 is 100.0.4896.20
    2022-03-23 13:35:00 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager.resolveDriverVersion(1093) -- Using chromedriver 100.0.4896.20 (resolved driver for Chrome 100)
    2022-03-23 13:35:00 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) -- Storing resolution chrome=100 in cache (valid until 14:35:00 23/03/2022 CET)
    2022-03-23 13:35:00 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) -- Storing resolution chrome100=100.0.4896.20 in cache (valid until 13:35:00 24/03/2022 CET)
    2022-03-23 13:35:00 [main] DEBUG i.g.bonigarcia.wdm.WebDriverManager.manage(1049) -- Driver chromedriver 100.0.4896.20 found in cache
    2022-03-23 13:35:00 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager.exportDriver(1148) -- Exporting webdriver.chrome.driver as C:\Users\boni\.cache\selenium\chromedriver\win32\100.0.4896.20\chromedriver.exe