0
<div class="list_details">
<p class="lnk_primary show_inline" rv-text="config.app.message.Label.abc.SmallScreen.58384" rv-on-click="current.eventGoToName">Add name</p>
</div>

I tried finding the link 'Add name' by using 'linktext' and 'partiallinktext' but it throws unable to locate element. I tried using classname but it also failed. Finally i used xpath to work.

My Code:

driver.findElement(By.linkText("Add name")).click();
driver.findElement(By.partiallinkText("name")).click();
driver.findElement(By.className("lnk_primary show_inline")).click();

Please let me know whether am i making any mistake?

Gurunathan
  • 13
  • 1
  • 4

2 Answers2

0

Sample program to find link using linktext :

     FirefoxDriver driver = new FirefoxDriver();

     driver.get("https://www.google.co.in/?gfe_rd=cr&ei=2FqBVNuuJOzV8gea24GwDA&gws_rd=ssl#q=google");

     driver.findElement(By.linkText("Google")).click();

please share your site URL so I can check.

Helping Hands
  • 5,292
  • 9
  • 60
  • 127
0

By.linkText and By.partiallinkText are only looking for the <a> tag. Since your link is in a <p> tag, it will not be found. Finding the element by xpath, like you have been able to do, is the better solution!

Based off experience and this question, By.className will not work for finding elements with more than one class. You could use xpath again or By.cssSelector instead to locate the element, such as:

By.cssSelector('.lnk_primary.show_inline')
Community
  • 1
  • 1