Reputation: 149
I'm using Selenium in C# to click on a link called 'Store Locator'. My current code is as follows but does not click on the link:
IWebElement storeLink = driver.FindElement(By.LinkText("Store Locator"));
Here is the original HTML, notice there is a span element nested in the tag, not sure if this makes a difference.
<a href="/site/olspage.jsp?id=cat12090&type=page&rdct=n" data-lid="hdr_stl"><span class="header-icon-storeFinder" aria-hidden="true"></span>Store Locator</a>
Upvotes: 0
Views: 1552
Reputation: 31
This will work for sure.
IWebElement storeLink = driver.FindElement(By.LinkText("Store Locator"));
storeLink.click();
Upvotes: 0
Reputation: 16201
Seems like the link is hidden. If even Selenium
finds the link it will not be able to interact directly. In that case JavaScript is your only option
By xpath = By.XPath("//span[contains(text(),'Store Locator')]");
IWebelement element = driver.FindElement(xpath);
((IJavaScriptExecutor)driver).ExecuteScript(@"arguments[0].click();",element);
Upvotes: 1