title: Get link text Selenium java
body: <p>I have problem with getting text of link.</p>
  
  <p>On site I have text link
  <code>&lt;a href="DetailsZZ-10048.html"&gt;ZZ-10048&lt;/a&gt;</code>, part with <code>ZZ-</code> is static, the number increments and it isn't known for me earlier. I need to get this number.</p>
  
  <p>I used looking at: <a href="https://stackoverflow.com/questions/20036485/get-link-text-selenium-java">Get link text - Selenium, Java</a> but there I have all links, URLs (not the text of the links)</p>
  
  <p>I also tried: <a href="https://stackoverflow.com/questions/22087952/how-to-gettext-of-an-element-in-selenium-webdriver">How to gettext() of an element in Selenium Webdriver</a> but I get on output <code>Printing null</code> everytime I changed and looked for a solution</p>
  
  <p>And the solution: <a href="https://stackoverflow.com/questions/29796984/java-selenium-how-to-get-linktext-anchor-from-link-webelement">Java Selenium, how to get linkText (anchor) from link WebElement</a> is not good also, because it doesn't recognise <code>"a[href*='ZZ-']"</code></p>
  
  <p>So, the closest one is:</p>
  
  <pre><code>List&lt;WebElement&gt; elements = driver.findElements(By.tagName("a")); 
  for (int i = 0; i &lt; elements.size(); i++) {
     System.out.println(elements.get(i).getAttribute("href"));
  }
  </code></pre>
  
  <p>but how can I change to view not only URLs, but names of the link? (especially one which starts from <code>ZZ-</code>)</p>