I have textview element (Not list view item) which is not visible . It is visible only when i swipe/scroll up. I am unable to click it as it is not visible. How can i scroll up and click on that item
Please explain me how can i scroll to that item and click it
Please provide full class as it will be useful to every one
Read the appium documentation. Look for scroll_to, and scroll_to_exact.
both scrolls are depricated (in java client :-)) )
@guru_lakshman_tomman java code examples:
// android
// in most cases will work
// by element id
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable())." +
"scrollIntoView(new UiSelector().resourceIdMatches(\".*id/your_element_id\"))"));
// by text inside
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable())." +
"scrollIntoView(new UiSelector().text(\"next_needed"))"));
// sometimes it is needed to specify scrolling view e.g. by className, but also possible by Id or whatever
"new UiScrollable(new UiSelector().className(\"android.widget.ScrollView\"))." +
"scrollIntoView(new UiSelector().resourceIdMatches(\".*id/your_element_id\"))"
// iOS
MobileElement el = driver.find....
// scroll down and to my element
assertTrue("failed scoll to my element :-*(", scrollToDirection_iOS_XCTest(el,"d"));
public boolean scrollToDirection_iOS_XCTest(MobileElement el, String direction) {
// The main difference from swipe call with the same argument is that scroll will try to move
// the current viewport exactly to the next/previous page (the term "page" means the content,
// which fits into a single device screen)
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
if (direction.equals("d")) {
scrollObject.put("direction", "down");
} else if (direction.equals("u")) {
scrollObject.put("direction", "up");
} else if (direction.equals("l")) {
scrollObject.put("direction", "left");
} else if (direction.equals("r")) {
scrollObject.put("direction", "right");
}
scrollObject.put("element", el.getId());
scrollObject.put("toVisible", "true"); // optional but needed sometimes
js.executeScript("mobile:scroll", scrollObject);
return true;
} catch (Exception e) {
return false;
}
}
// or just scroll to some text
public boolean tapItemByDescription(String text) {
System.out.println(" tapItemByDescription(): " + text);
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 + "'");
return tapElement((MobileElement) el);
}