How to Detect Text in a Hybrid App?
Appium Desktop: 1.6.1
Appium Server: 1.8.1
java-client: 6.1.0
I have been trying different ways, however none of them appear to be working 100%. One thing I tried was to use element.isDisplayed() on a xpath like this “//div[contains(text(),’” + text + “’)]”. This worked but only for div elements. It certainly does not work on any span elements even if I were to change div to span.
Here is the span element I am unable to access. Even with the full xpath copies straight from the Chrome inspector I was unable to even reach the element and so I definitely cannot check the text inside if the Xpath fails.
Here is the second method I tried:
public boolean searchForText(String text, String xpath, int wait)
{
boolean result;
System.out.println("Searching for: " + text);
WebElement target = findByXPath(xpath, BUTTON_WAIT);
String actual = target.getText();
System.out.println("Actual: " + actual);
if(actual.equals(text)){
result = true;
}else {
result = false;
}
System.out.println("Found: " + result);
return result;
}