title: How to get count of Selenium XPath results
body: <p>As of now I am getting the count of the number of matching results using <code>listChanges.size()</code> . How do I directly get the count without loading <code>getChanges</code> in the list? </p>
  
  <pre><code>By getChanges = By.xpath("//td[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]");
  
  List&lt;WebElement&gt; listChanges = driver.findElements(getChanges);
  </code></pre>
  
  <p>I found this(<a href="https://stackoverflow.com/questions/1985453/count-function-in-xpath?rq=1">Count function in XPath</a>) and I tried the below which does not work! </p>
  
  <pre><code>Integer getCount = By.xpath(count("//td[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')]"));
  </code></pre>
  
  <p>Looks like I have to do something like this.</p>
  
  <pre><code>Integer getCount = By.xpath("count(//td[contains(@class,'blob-code blob-code-addition') or contains(@class,'blob-code blob-code-deletion')])");
  </code></pre>
  
  <p>But the right hand side returns an object of type <code>By</code></p>