title: How to get links from web page using selenium
body: <p>Is there any way we can get the link location of webelement. I know we can get the text from webelement and also by using getAttribute("href") method we can location of link for href link. But my requirement is to get all the link. For example,  </p>
  
  <pre><code>1.&lt; a href="http://www.java2s.com/"&gt;Example&lt;/a&gt; 
  2. &lt; a onclick="Test.TestFunction("9","testNumber","2");" style="cursor:pointer"&gt;This is text display on page&lt;/a&gt;. 
  </code></pre>
  
  <p>I have user below given code:</p>
  
  <pre><code>public void getAlllink(){
      tcount = driver.findElements(By.tagName("a"));
      System.out.println("Total Links on page :"+tcount.size());
      for(WebElement we:tcount){
      System.out.println("Link: "+str);//display element but not link.
      we.click(); //This click on link 
      System.out.println(we.getText()); //display text code that fetched by selenium and not link text
      System.out.println(we.getAttribute("href"));//display only one link http://www.java2s.com/
  }
  </code></pre>
  
  <p>Is there any way to get the link location for both the element. One is simple link and another is link which is generated on call of JavaScript function.</p>