<a href="editauthority.jsp" title="Add a new connection" class="link btn btn-primary" role="button">
<i class="fa fa-plus-circle fa-fw" aria-hidden="true"></i>
Add a new connection</a>
I have an HTML element as above with an font-awesome icon. I want to find an element from html using its text.
This is what I have tried so far
//a[contains(@class,'btn') and contains(normalize-space(text()),'Add a new connection')]
But the problem is //a[contains(@class,'btn') and contains(normalize-space(text()),'')]
returns the expected value with a new line before and few space at the start, which doesn't match with the expected value of Add a new connection
How can I match the element text ignore all new line and extra spaces.
I am using the above XPATH to find elements in selenium testing.
Update
Adding Selenium code
/**
* Clicks a button based on visible text, this type of button is created using anchor tag with .btn class
* @param text
*/
public void clickButton(String text)
{
WebElement element =
waitElementClickable(
By.xpath("//a[contains(@class,'btn') and contains(normalize-space(text()),'" + text + "')]"));
element.click();
if (!isAlertPresent())
{
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loader")));
}
}