0

I declared an array of elements using this method:

checkboxes = self.driver.find_elements(AppiumBy.XPATH, '//XCUIElementTypeButton[@name="Square"]')

How do I find the sibling element to the first element in the array?

This

siblingElement = checkboxes[0].find_element(by=AppiumBy.XPATH, value='./following-sibling::XCUIElementTypeStaticText')

failed with the following error message:

NoSuchElementError: An element could not be located on the page using the given search parameters.

I tried using this documentation:

https://appium.io/docs/en/commands/element/find-elements/

https://appium.io/docs/en/commands/element/find-element/

Please note I'm using Python in my framework.

Domain of the UI:

<XCUIElementTypeButton type="XCUIElementTypeButton" name="Square" label="Square" enabled="true" visible="true" accessible="true" x="15" y="428" width="20" height="21" index="22"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="checkbox 1 text" name="checkbox 1 text" label="checkbox 1 text" enabled="true" visible="true" accessible="true" x="43" y="428" width="308" height="18" index="23"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Square" label="Square" enabled="true" visible="true" accessible="true" x="15" y="478" width="20" height="21" index="24"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="checkbox 2 text" name="checkbox 2 text" label="checkbox 2 text" enabled="true" visible="true" accessible="true" x="43" y="478" width="260" height="35" index="25"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Square" label="Square" enabled="true" visible="true" accessible="true" x="15" y="542" width="20" height="21" index="26"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="checkbox 3 text" name="checkbox 3 text" label="checkbox 3 text" enabled="true" visible="true" accessible="true" x="43" y="542" width="333" height="86" index="27"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Square" label="Square" enabled="true" visible="true" accessible="true" x="15" y="657" width="20" height="21" index="28"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="checkbox 4 text" name="checkbox 4 text" label="checkbox 4 text" enabled="true" visible="true" accessible="true" x="43" y="657" width="320" height="52" index="29"/>
kevin
  • 37
  • 5
  • 21

1 Answers1

0

First case

 def tap_by_index(self, locator_string, index):
        locator = self.get_locator(locator_string)
        if str(locator_string[0]).startswith("xpath"):
            self.driver.find_elements(AppiumBy.XPATH, str(locator))[index].click()

 def get_locator(locator):
     exploited_locator = locator[1]
     return exploited_locator


Second case

  def tap_by_index(self, locator: Tuple[By, str], i: int):
        """i: element index"""
        self.wait(locator) # WAIT UNTIL VISIBLE
        elements = self.driver.find_elements(*locator)
        elements[i].click()