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)
table = FindsByClassChain('**/XCUIElementTypeTable/XCUIElementTypeCell/XCUIElementTypeStaticText)
or
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
table[0].click()
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:
table.click()
FindByPredicate("name == 'back'").click()
for element in table:
table.click()
driver.back()