1
votes

[Context]
Appium 1.6.5
XCode 8.3.3
iOS 10.3
Python 2.7

I am experimenting with Appium with a basic iOS app created off of the XCode template that creates a Tabbed Application. My app was created off of that template that essentially has a Tab Bar Controller with 2 tabs pre-set. Each tab displays a different View. Each View has 2 labels with some text on them.

[Goal]
I want to write an Appium script that navigates to a particular tab, then reads the text of one of the labels.

[Issue]
I am able to locate the elements up to (and including) the view corresponding to the selected tab. But, I do not see any element that is inside that view.

I have tried to use both ID and XPATH with the same results.

Note: each element I am trying to access has Accessibility enabled and an Accessibility ID set. Every Accessibility ID I have set is unique.

[Question]
How can I access the label in question with Appium? Or even better, any of the elements of my view?

[Output of driver.page_source]

    <?xml version="1.0" encoding="UTF-8"?><AppiumAUT><XCUIElementTypeApplication type="XCUIElementTypeApplication" name="MyTestApp" label="MyTestApp" enabled="true" visible="true" x="0" y="0" width="375" height="667">
      <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="0" width="375" height="667">
        <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667">
          <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667">
            <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667">
              <XCUIElementTypeOther type="XCUIElementTypeOther" name="view1" enabled="true" visible="true" x="0" y="0" width="375" height="667"/>
            </XCUIElementTypeOther>
          </XCUIElementTypeOther>
          <XCUIElementTypeTabBar type="XCUIElementTypeTabBar" enabled="true" visible="true" x="0" y="618" width="375" height="49"/>
        </XCUIElementTypeOther>
      </XCUIElementTypeWindow>
      <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="false" x="0" y="0" width="375" height="667">
        <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="667"/>
      </XCUIElementTypeWindow>
      <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="0" width="375" height="667">
        <XCUIElementTypeStatusBar type="XCUIElementTypeStatusBar" enabled="true" visible="true" x="0" y="0" width="375" height="20">
          <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="20"/>
          <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="20">
            <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="6" y="0" width="39" height="20"/>
            <XCUIElementTypeOther type="XCUIElementTypeOther" value="SSID" name="3 of 3 Wi-Fi bars" label="3 of 3 Wi-Fi bars" enabled="true" visible="true" x="50" y="0" width="13" height="20"/>
            <XCUIElementTypeOther type="XCUIElementTypeOther" name="10:35 AM" label="10:35 AM" enabled="true" visible="true" x="161" y="0" width="56" height="20"/>
            <XCUIElementTypeOther type="XCUIElementTypeOther" name="-100% battery power" label="-100% battery power" enabled="true" visible="true" x="337" y="0" width="33" height="20"/>
          </XCUIElementTypeOther>
        </XCUIElementTypeStatusBar>
      </XCUIElementTypeWindow>
    </XCUIElementTypeApplication></AppiumAUT>

View1 is one of my two views, and as you can see in the XML above, it doesn't seem to contain any of the labels in that view:

<XCUIElementTypeOther type="XCUIElementTypeOther" name="view1" enabled="true" visible="true" x="0" y="0" width="375" height="667"/>

[Python Code]
Here is the code I am using:

driver = webdriver.Remote(get_appium_server(), desired_capabilities=get_capabilities())
driver.find_element_by_id('view1')       # This works fine
driver.find_element_by_id('view1label1') # The code fails here despite the fact that this accessibility ID exists for one of the labels underneath 'view1'

When I run it, I get the following error:

Traceback (most recent call last):
  File "/some_path/Appium.py", line 33, in <module>
    mypythonappiumfunction()
  File "/some_path/Appium.py", line 28, in mypythonappiumfunction
    driver.find_element_by_id('view1label1') # The code fails here despite the fact that this accessibility ID exists for one of the labels underneath 'view1'
  File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 289, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 791, in find_element
    'value': value})['value']
  File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/some_path/robot/lib/python2.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.`

[Screenshot of the app]
XCode Storyboard

[XCode accessibility properties of the Label I am trying to access]
Label properties in XCode

1

1 Answers

0
votes

I finally got to the bottom of this and found out why the elements contained inside my view were not visible/accessible. The issue was that I enabled "Accessibility" for everything including the view itself.

When you make the view accessible, it treats the view as one single big container that you can access, but you then lose access to the elements contained within that view.

By simply disabling "Accessibility" (unchecking the box in XCode) for my view, I started to see the elements contained within that view.