Reputation: 1
<a ui-sref="apps.service" href="#/apps/service">
<i class="glyphicon glyphicon-list icon zoom-icon text-info-dker"></i>
<span class="font-bold"> Service</span>
</a>
How can I locate the element?
driver.findElement(By.partialLinkText("service")).click();
driver.findElement(By.xpath("ui[href$=services]"));
Upvotes: 0
Views: 192
Reputation: 111786
This XPath,
//a[normalize-space() = 'Service']
will select all a
elements whose normalized string value equals "Service" -- perfect for the example you show.
Be wary of solutions based upon contains()
as they will also match strings that include additional leading or trailing text, which may or may not be what you want.
Upvotes: 0
Reputation: 396
It is better to use contains in to locate element in this xpath. The below xpath will be accurate.
driver.findElement(By.xpath("//a/span[contains(text(),'Service')]")
Upvotes: 0
Reputation: 23845
You should try using xpath
with WebDriverWait
to wait until element visible and enable as below :-
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath(".//a[contains(.,'Service')]"))).click();
Upvotes: 0
Reputation: 51009
partialLinkText
is case sensitive. Try
driver.findElement(By.partialLinkText("Service")).click();
The element is in <a>
tag, not <ui>
tag
driver.findElement(By.xpath(".//a[href*='services']"));
Upvotes: 1