How can I get this 'Version: 0.1.0 - 94" value from the <div> tag in selenium webdriver?

  • How can I get this Version: 0.1.0 - 94 value from the


    tag in selenium webdriver? and here is my code:

    <div _ngcontent-qbk-c3="" style="text-align: center;">Version: 0.1.0 - 94</div>

  • As far as I can understand, your issue is to extract version number to use it further in the test. So unless you have some context you could go from in order to build proper and reliable xpath, I would suggest to use following approach:

    1. Extract the tag assuming there is no places where divs have "Version" word:var version = element(by.xpath('//div[contains(., 'Version:')]'));

    2. Get full version text and parse out the required part (example can be found here)

    Above is the example for protractor. If we are talking about Java, then you could use something like this:

    String versionNumber = driver.findElement(By.xpath("'//div[contains(., 'Version:')]")).getText();
    Pattern pattern = Pattern.compile("^Version:\\s(.+)$");
    Matcher m = pattern.matcher(versionNumber);
    String clearedVersion = "";
        clearedVersion =;

    The code above preserves version number to the clearedVersion variable.

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2