In my Android app, I need to scroll down the screen and validate whether the required elements(each individual element) are available or not. How do I achieve this with one method in Java?
Android - Is there a single method to Scroll and validate the required set of elements are available
In Android elements that are not visible are not added into the hierarchy - so if it’s not visible then you don’t know if it exists. these are the approaches that I’ve seen so far:
1: scroll by passing coordinates and then check if element exits (http://appium.io/docs/en/commands/interactions/touch/scroll/)
2: scroll by using screen ratios (How to perform scroll/swipe top to bottom)
I took another approach:
get parent element -> get all child elements (you can get only the visible ones) -> scroll from last element to first element -> get all new child elements -> compare new elements with old elements (if both are the same then you have reached the end of the list)
@LyubomirStoimchev , Hi I was also facing the similar issue and thanks for your suggestion but when am writing the code to scroll to the element(which is still visible on the screen) its not scrolling
I have the list of elements(example 10) but the appium shows 7 elements but the screen shows 6 elements now I need to scroll to 7th element to see the remaining 3 elements.
When I use the below snippet its not scrolling to the 6th element , not sure if its because the 6th element is visible, however if I provide the text of 7th element which is not visible in the screen then the scrolling works.
‘new UiScrollable(new UiSelector().resourceId(“com.android.settings:id/dashboard_tile”).instance(6)).scrollIntoView(new UiSelector().className(“android.widget.TextView”));’)
I can’t pass the text of the element as its dynamic so I need to take the list of elements and move to the last element.
Is there any suggestions or am I doing any wrong in the above code? Can you please help me with this
@latchookarthi Have you tried mobile commands? https://appium.io/docs/en/commands/mobile-command/it
You can try also this(I don’t think it will work but it’s worth a shot)
IWebElement element = FindElement(locator);
string script = “arguments.scrollIntoView(true);”;
thanks for the response @LyubomirStoimchev but it didn’t work and also the link which u provided came as 404 not found
In the page check the scroll command documentation.
Did you find or created it? I am looking too. I need to verify are elements displayed then scroll, verify again, then scroll again if need it, etc.