I am tryting to get the element using the link text but unable to find the element getting error regarding the linktext

enter image description here
enter image description here

  • You can try locating element <a> first by using its unique title attribute, then proceed with locating element <span> – Yu Zhang Dec 13 '17 at 6:18
  • i have try but not working.getting same error – Rutvi Soni Dec 13 '17 at 6:21
  • 1
    Can you add the code what you tried so far, So we can help you out – NarendraR Dec 13 '17 at 7:07

It's likely that since the text has a leading blank, it is not finding a "match." I suggest you use partialLinkText instead:

WebElement myAccount = driver.findElement(By.partialLinkText("My Account"));
| improve this answer | |

In automation testing company we perform different approaches to find/get the web-element. In your case link text is not working because there is space before " My Account" text.

So you can use Below approaches that can help you

1.driver.findElement(By.xpath(//ul[@class='mega-menu']//li//a//span(contains(text(),'My Account')));
2.driver.findElement(By.partialLinkText("My Account"));
3.driver.findElement(By.LinkText(" My Account"));
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.