title: How to test 2 different links with same text?
body: <p>I was testing if the link exists on a web page. For that I am testing if that particular text for ex <code>"Selenium Videos"</code> is in <code>&lt;a&gt;&lt;/a&gt;</code> tag or not. But there are  two same links such as --<code>"How to Master QTP?"</code> on the page one in menus and second in <code>Recent free LIVE webinars</code> on right hand side of the page. I don't know how to test these two different links having same link text. Using the function written below, it will return true if I am searching second link text but it will find first link text. Please help.</p>
  
  <p>I am using following function to test links.</p>
  
  <pre><code>public static String checkLink(WebDriver driver,String linkText)
      {
          //purpose : check if the link for text is available 
          //ip: driver,xPath,Data
          try
          {
  
          List &lt;WebElement&gt; links = driver.findElements(By.tagName("a"));
          for(WebElement we : links) 
          {
             if(linkText.equals(we.getText())) 
             {
                  System.out.println("Link text from excel is:" + linkText);
                  System.out.println("Link text from element is:" + we.getText());
  
                return "Pass";
             }//if
          }//for
      }
      catch(Exception e)
      {
          return "Fail";
      }//catch
      return "Fail";
  }//enter text
  </code></pre>