Cannot click the second element in a list of elements found by Predicate / Class Chain

I am doing an automation test in iOS device with python 3 and facing a problem:

To simplify, there are 5 elements with the name start with happy in a page (lets call it page A) only, of which all 5 elements can be found by 2 ways successfully:

FindsByClassChain = lambda classchain: driver.find_elements_by_ios_class_chain(classchain)
FindsByPredicate = lambda predicateString: driver.find_elements_by_ios_predicate(predicateString)

  1. table = FindsByClassChain('**/XCUIElementTypeTable/XCUIElementTypeCell/XCUIElementTypeStaticText)


  1. table = FindsByPredicate("name BEGINSWITH 'happy')

My goal is to perform click action on each element, and I managed to click any elements by this code as well:

table[a number ranging from 0 to 4].click()

After clicking one of the elements, the app will turn to next page (page B), and therefore I need to click the ‘back’ button on the page B to go back to page A for clicking the remaining element.

so the code is

FindByPredicate("name == 'back'").click()
table[1].click()   # Fail to perform this click action

The problem is that the click action of second element fail.

But this code(method) works in Android, please advise the solution, thanks a lot!

P.S. I even try to use ‘loop’ to perform click on each element in both iOS and Android devices, the result are the same ( iOS: failed when clicking second element, Android: successful to click all 5 elements), the code for both iOS and Android are:

for element in table:
   FindByPredicate("name == 'back'").click()
for element in table:

it will not work like this. change approach to search elements after each screen change.

1. search elements with text 'happy'
2. tap on first el
// screen changes. is it?
3. search and tap back button
4. search elements with text 'happy'
5. tap on second el
6. search and tap back button
1 Like

Thanks for your prompt reply. Your approach is feasible.

But i wonder is it the limitation on iOS device? as when it comes to Android, I just need to find the element once, and it can be leveraged in every click action even after each screen change,