2

I want to know the following information from my current running ChromeDriver:

  • exact temporary user-data folder that ChromeDriver created by default
  • the driver version

    According to this page, It should be part of the ChromeDriver's returned capabilities:enter image description here

    What I tried so far:

    Capabilities caps = DesiredCapabilities.chrome(); System.out.println(caps.getCapability("userDataDir")); System.out.println(caps.getCapability("chrome.chromedriverVersion")); 

    Both are giving me null. I do know that I'm not manually setting the ChromeOptions "--user-data-dir" but still, I know that ChromeDriver will use a certain directory by default.

    Same goes with the version, It makes sense that we can retrieve the current driver's version at will right?

    What am I missing here?

    Thanks in advance!

    UPDATE 1:
    I'm calling the code above right before passing the caps instance as a parameter to the ChromeDriver constructor.

    Here's a slightly more insightful snippet:

    public class Driver implements WebDriver { private WebDriver webDriver; private Capabilities caps; public Driver(){ caps = DesiredCapabilities.chrome(); caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true); caps.setCapability(CapabilityType.SUPPORTS_ALERTS, true); caps.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true); //Am I not doing this correctly? System.out.println(caps.getCapability("userDataDir")); System.out.println(caps.getCapability("chrome.chromedriverVersion")); webDriver = new ChromeDriver(caps); } } 

    UPDATE 2: Regarding the version number, I realized that whenever I do

    Capabilities caps = DesiredCapabilities.chrome(); 

    the DesiredCapabilities class is passing a blank string as a parameter to the version number.

    enter image description here
    enter image description here

    With that said, is there any way I can get the current chrome driver version (boxed below)? I know this information is stored somewhere but I do not know how to get it.

    enter image description here

    As for the temporary user-data folder, I still have no idea how to get it even after watching the capabilities and the webdriver object created.

    Appreciate the help!

  • 2
    • Can you consider updating us exactly at which point are you trying to read the capabilities? ThanksCommentedJun 19, 2017 at 13:58
    • @DebanjanB I have updated my question with a slightly more insightful snippet. Hope my update helps..TIA!
      – iamkenos
      CommentedJun 19, 2017 at 14:35

    2 Answers 2

    4

    Thanks to @MikeJRamsey56's casting tip, I managed to figure this out.

    Here's a dirty (but) working solution. Hope this can help others out.

    public class Driver implements WebDriver { private WebDriver webDriver; private Capabilities caps; public Driver(){ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "the/driver/path/chromedriver.exe"); caps = DesiredCapabilities.chrome(); webDriver = new ChromeDriver(caps); //Cast webDriver instance to RemoteWebDriver caps = ((RemoteWebDriver) webDriver).getCapabilities(); //Call getCapability and cast to Map. //This line will give a Type Safety warning, hence the "dirty" in my solution. Map<String, String> a = (Map<String, String>) caps.getCapability("chrome"); System.out.println(String.format("Driver Version: %s", a.get("chromedriverVersion"))); System.out.println(String.format("Temp dir: %s", a.get("userDataDir"))); } } 

    Output:
    enter image description here

      0

      My initialization logic looks like this:

      DesiredCapabilities capabilities = null; System.setProperty("webdriver.chrome.driver", user_dir + "/src/main/resources/drivers/ChromeDriver/chromedriver"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.addArguments("--disable-extensions"); options.addArguments("--disable-infobars"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); prefs.put("excludeSwitches", "enable-automation"); options.setExperimentalOption("prefs", prefs); capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("version", "latest"); capabilities.setCapability("browserName", "chrome"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); try { webDriver = new ChromeDriver(options); } catch(Exception e) { System.out.println("**>uh-oh " + e.getMessage()); } webDriver.manage().deleteAllCookies(); Capabilities cap = ((RemoteWebDriver) webDriver).getCapabilities(); String browserName = cap.getBrowserName(); String browserVersion = cap.getVersion(); System.out.println("Browser name=" + browserName + ", version=" + browserVersion); 
      3
      • When you do capabilities.setCapability("version", "latest");, will cap.getVersion(); give you "latest" or the boxed number on my question (UPDATE 2)?
        – iamkenos
        CommentedJun 21, 2017 at 1:59
      • Gives the actual version of the Chrome browser. The key is to cast to class RemoteWebDriver.CommentedJun 21, 2017 at 16:33
      • Sorry but this is not the answer I am looking for. Although the casting tip helped me figure it out so I'll upvote this at least. Thanks a bunch!
        – iamkenos
        CommentedJun 26, 2017 at 14:46

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.