I have a requirement, where I need to traverse through all the matching xpath & match the count with a defined number.
The requirement seems straight forwards but the problem I am facing is, Get Element Count or Get Matching Xpath Count returns the list of elements present in the screen view. i.e. there are more elements matching the Xpath, but for that i need to scroll down on my mobile device for a native app.
I would like to know, if there is a way i can get the element count without using the scroll action.
To tell you more about the behaviour, Appium inspector captures the screenshot for the screen and then Get Element Count or Get Matching Xpath Count returns the list of elements present only in the view of inspector. However, Get Element Count or Get Matching Xpath Count should not depend on the screen view rather it should match with all the elements matching the xpath similar to what is there in web browser for UI automation.
If your xpath gives you a list of matches then you can use the built-in library’s Get Length to give you the number of items in the list if that’s all you need?
If you need to count the items from the list that contains a specific value then Get Count or Collections Library’s Get Match Count might be usefull.
What happens when you do it manually? do only 4 items show on the screen, and you need to swipe to show the two hidden elements?
Is this something thats screen size dependant? i.e. if you tested with a larger device’s screen size would all 6 items show without scrolling?
I’m suspecting it’s your app is only loading 4 items (because that’s all thats initially visible) and this is why your xpath count is 4, and then the swipe action triggers an event to load the next page of 4 items (but you only have 6 so only 2 are returned)
Which library are you using? I don’t have much experience with mobile apps (Appium?) but if it’s just a web site being displayed on a mobile device I probably can help.
That’s exactly the behaviour with my native mobile app. I am aware of traversing through list of items using xpath that matches visible & invisible items (i.e. the items that requires scroll).
However, Get Element Count returns only the list of visible items on the mobile app. That’s quite strange to me.
To answer your question, i am using AppiumLibrary and the app loads all the 6 items at once. But only 4 of them are visible on the screen & hence Get Element Count returns 4. But, if i scroll down to the end, i get to see the other 2 elements as well.
I don’t think so, scrolling everytime is the best option to get list of elements. Moreover, i have to check the duplicate enteries as well (if scroll is the only option left)
I have come across few stackoverflow threads & there seems to be a limitation. Do you know if there is a workaround to bypass this?