HTML Code:
<div class="deviceName truncate"><a ng-href="#" href="#" style="">Hello World</a></div>
Each <a>
element, the Link text contains double space as "Hello World"
Retrieving information, in List
List<WebElement> findAllUserName = driver.findElements
(By.xpath("//div[@class='deviceName truncate']//a[text()]"));
for (WebElement webElement : findAllUserName) {
String findUSerText = webElement.getText();
System.out.println(findUSerText);
}
Its gives list Result with single space, "Hello World"
How should overcome to this situation ? To compare text,
Concern behind this, wants to compare list element with given string :
driver.findElement(By.xpath("//div[@class='deviceName truncate']//a[contains(text(),'" + name + "')]"))
And its considering double space,