I usually try to avoid XPATH in my tests, hence to search for Elements by Text I am doing something like this, which will return a By
element to be used in the webdriver interaction.
public static By byText(final String text)
{
switch (Configuration.getInstance().getPlatform())
{
case ANDROID:
// This requires a UiAutomator2 test driver:
return MobileBy.AndroidUIAutomator("new UiSelector().text(\"" + text + "\")");
case IOS:
default:
throw new RuntimeException("not implemented");
}
}
Unfortunately I don't know the equivalent to iOS just now, but it should also be possible somehow ;)