I'm new to mobile automation and trying to figure out how to put certain element from the list into the view and perform tap on it.
so far I did it for Android where only the elements are visible when it in-view so we can use scrollToView for them and then pick those if you find them on one on view
however in iOS I can see all the element in Appium even though they are not in the view but problem is I can't tap and scroll to that particular element
is it possible to make List of all the element then scroll into view to that particular element by looping to the child elements?.the below given code is working fine for the Android but not working for iOS this is my same code which is for android and working..
if(!isElementPresent(by("label.details_key",ImmutableMap.of("index","2"))))
scrollToMyView;
Private void scrollToMyView()
{
Dimension dimensions = getDriver().manage().window().getSize();
int Startpoint = (int) (dimensions.getHeight() * 0.7);
int scrollEnd = (int) (dimensions.getHeight() * 0.3);
int mid = (int) (dimensions.getWidth() * 0.5);
new TouchAction(getDriver()).press(PointOption.point(mid, Startpoint)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(mid, scrollEnd)).release().perform();
label("scroll");
hardWait(2000);
}
this one I tried for iOS ... but is not working in this why do I have any workaround ?
public boolean swipeToDirection_iOS_XCTest(MobileElement el, String direction) {
try {
JavascriptExecutor js = (JavascriptExecutor) getDriver();
HashMap<String, String> swipeObject = new HashMap<String, String>();
if (direction.equals("d")) {
swipeObject.put("direction", "down");
} else if (direction.equals("u")) {
swipeObject.put("direction", "up");
} else if (direction.equals("l")) {
swipeObject.put("direction", "left");
} else if (direction.equals("r")) {
swipeObject.put("direction", "right");
}
swipeObject.put("element", el.getId());
js.executeScript("mobile:swipe", swipeObject);
return true;
} catch (Exception e) {
return false;
}
}
MobileElement el = getDriver().findElement(by("tab.posted_trans"));
if(swipeToDirection_iOS_XCTest( el, "down"));
getDriver().findElement(by("tab.posted_trans")).click();