I am tryting to get the element using the link text but unable to find the element getting error regarding the linktext
-
You can try locating element <a> first by using its unique title attribute, then proceed with locating element <span>– Yu ZhangCommented Dec 13, 2017 at 6:18
-
i have try but not working.getting same error– Rutvi SoniCommented Dec 13, 2017 at 6:21
-
1Can you add the code what you tried so far, So we can help you out– NarendraRCommented Dec 13, 2017 at 7:07
Add a comment
|
2 Answers
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"));
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"));