// android
public boolean scroll_and_tap_byText(String text) {
try {
WebElement el = driver.findElement(MobileBy
.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().text(\""+text+"\"));")));
// tap on it
} catch (Exception e) {
return false;
}
}
// ios
public boolean scroll_and_tap_byText(String text) { //works ONLY inside scrollView
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap<>();
scrollObject.put("predicateString", "value == '" + text + "'");
js.executeScript("mobile: scroll", scrollObject);
WebElement el = ((IOSDriver) driver).findElementByIosNsPredicate("value = '" + text + "'");
// now tap on it
}
1 Like