IOS + Accessing control not in view

Hi,
On IOS, I want to access a control which currently is not on screen(View)…But will appear after scrolling
So, do I need to perform scroll and reach to that control before performing any actions on it OR
appium or uiautomator is intelligent enough to identify and perform action on it without performing scroll

Thanks,
Nishant Shah

In iOS, you should be able to get elements which are not in the view. If you want to click/tap them, you should scroll them into view first. You can try using the scrollTo command, or try generating touchActions which swipe the screen.

On Android, you need to use other methods to find elements which aren’t visible. There is a method for scrolling to an element based on matching the text the element contains.

Scrolling and off-screen elements are handled very differently on iOS and Android, we are working on ideas for a better way of handling them. Any suggestions?

Here is how a access elements that are not currently in view in my iOS project.

    WebElement deviceSection = driver.findElementByAccessibilityId(deviceType);
    JavascriptExecutor js= driver;

    String elementID = ((RemoteWebElement) element).getId();
    HashMap<String , String>[] object = (HashMap<String , String>[]) new HashMap[1];
    HashMap<String, String> map = new HashMap<>();
    map.put("element" , elementID);
    object[0] = map;
    js.executeScript("mobile: scrollTo", object);

Hope this helps :smile:

1 Like

I don’t understand this line:
String elementID = ((RemoteWebElement) element).getId();

getId() returns what exactly? it appears to be returning the id of an unitialized RemoteWebElement object.

My problem: I cannot look for the existence of an element that is not in view. When I do, I get the exception below. All I want to do is to scroll to the bottom of the table. That will make the element of interest visible, and I can access it no problem. Is there a way to simply scroll to the bottom or top of a table?

Unhandled error: TypeError: Cannot read property ‘status’ of undefined
at null. (/usr/local/share/npm/lib/node_modules/appium/lib/devices/ios/ios-controller.js:169:19)
at Object.cb [as callback] (/usr/local/share/npm/lib/node_modules/appium/lib/devices/ios/ios-controller.js:239:5)
at next (/usr/local/share/npm/lib/node_modules/appium/node_modules/async/lib/async.js:801:43)
at /usr/local/share/npm/lib/node_modules/appium/node_modules/async/lib/async.js:32:16
at null. (/usr/local/share/npm/lib/node_modules/appium/lib/devices/ios/ios.js:1273:36)
at Object.q.process [as _onImmediate] (/usr/local/share/npm/lib/node_modules/appium/node_modules/async/lib/async.js:809:21)

Simple scrollToBottom and scrollToTop methods (or swipeToBottom and swipeToTop) would be nice. it would make it easy to get to the bottom or top of a table. Then we could see elements that are not initially visible.

Ah yes, scrollToBottom and scrollToTop would be nice. But take a look at the methods available here:
https://developer.apple.com/library/ios/documentation/ToolsLanguages/Reference/UIAScrollViewClassReference/index.html#//apple_ref/doc/uid/TP40009912
and here:
http://developer.android.com/tools/help/uiautomator/UiScrollable.html

That’s what we have to work with. As you see, android provides scrollToBeginning and scrollToEnd methods, but iOS leaves us with less-nice methods.

I guess if we wanted to have a way to hack it into the client, we could get the first item in the scrollview, then scroll to that item. implement it as a “scrollToTop” function.

Want to try it out? @Jeffrey_Blaze

I’m seeing in iOS 8 that a view that is not visible is no longer being found. That’s changed for sure from iOS 7.1 --I have scrollTo functionality that is broken now because of the change.

Anyone else notice this in iOS 8?

Hi @jonahss - do we have any udpates on this? I am interested in accessing elements that are not viewable in screen in both iOS and Android.