In in our mobile app, there are two boxes with the same AutomationId.
For automated testing i need to find the first of the two elements by xpath.
I tried following code, bt it didn’t work:
self.driver.find_element_by_xpath( "xpath=(//[@contentDescription='Cards'])").click() time.sleep(0.5) self.assertEqual('Angle x:', self.driver.find_element_by_accessibility_id('MovementsTitle').text) time.sleep(0.5)
You can handle the following way
els = self.driver. find_elements_by_xpath('xpath=(//[@contentDescription='Cards'])') els.click()
First, get the all identical elements through “find_elements” this will give you as an array of elements then you can perform the actions accordingly