Reputation: 11
I am trying to automate an web application using Selenium Webdriver and C#. Currently I am stuck with a simple issue. After navigating to a particular page, I am trying to click a link which has a link text of "Manage groups". However when I am executing the test it is failing to find the element in the web page.
driver.FindElement(By.LinkText("Manage groups"));
I also tried using absolute Xpath:
driver.FindElement(By.XPath("html/body/div[1]/div[1]/div[2]/div[2]/article/li[2]/a"));
In both the cases the test navigates to the page then fails with error:
unable to find the element
Upvotes: 1
Views: 1426
Reputation: 9
The issue may be caused by a small mistake in 'Manage groups' text (e.g. there may be an addition whitespace).
Can you please provide at least little part of html (you can get it by right-click on your 'Manage groups' link and selecting 'Inspect Element' option )
if not - try these ones:
By.XPath("//a[@contains(., 'Manage groups')]")
By.XPath("//a[@contains(., 'manage groups')]")
By.XPath("//a[@value='Manage groups')]")
By.partialLinkText("Manage groups")
Upvotes: 1
Reputation: 142
It should work with that :)
IWebElement ClickNext = driver.FindElement(By.XPath("//a[.='Manage groups']"));
// We get the link to click on
ClickNext.Click();
Edit : Try that li
instead of a
IWebElement ClickNext = driver.FindElement(By.XPath("//li[.='Manage groups']"));
// We get the link to click on
ClickNext.Click();
Upvotes: 0