Xpath incorrect in page source (python, appium 1.3.4)

python 2.7.6
appium 1.3.4
osx Yosemite (10.10.1)
xcode 6.1.1
ios 8.1

What I found investigating this question is that the xpath is being reported by page source incorrectly for two reasons:
a) it’s zero-based
b) the very first AppiumAUT and UIAApplication elements are siblings, not parent/child, as reported by get_source:

    <UIAApplication name="myapp" label="myapp" path="/0" >
        <UIAWindow name="Main Window" label="Main Window" path="/0/0" >
            <UIAImage name="____name" label="" path="/0/0/0" >
            <UIAButton name="nav_profile_button" label="navmenu image default" path="/0/0/1" >
                <UIAImage name="navmenu_image_default" label="" path="/0/0/1/0" >

so it should look like:

<AppiumAUT path="/1" >
<UIAApplication name="myapp" label="myapp" path="/2" >
    <UIAWindow name="Main Window" label="Main Window" path="/2/1" >
        <UIAImage name="____name" label="" path="/2/1/1" >
        <UIAButton name="nav_profile_button" label="navmenu image default" path="/2/1/2" >
            <UIAImage name="navmenu_image_default" label="" path="/2/1/2/1" >

I’m pretty sure it’s zero based because the code that uses the path indexes into an array. For example if we have one window with a path of “/0” then the code would access it via element_array[0]. If you want to convert the path string to use in xpath directly then yes, you’d need to add one as XPath itself starts at 1.

Do you think this XML is coming (more or less) directly from instruments? i.e. it’s an Apple issue? If so, I guess we may as well close.

appium controls the XML. I think this is working as designed and isn’t a bug.

Ok, I certainly wouldn’t argue with you, being one of the appium authors, it just seems like it has pretty high potential to cause confusion, especially being named ‘path’ and not ‘indices’ or something else… just my .02

I agree it’s potentially confusing. The docs should probably be improved to explain the XML structure better. If you feel strongly about renaming the attribute then feel free to submit an enhancement request on GitHub and the appium devs will review.

Heard. Maybe at some point I will have the time…
Should probably close for now-

@jwallis Someone else asked the same question so I added some docs.