How can I get the xpath from an element (or other way of getting an element's parent)?

page_source() displays the path so there should be some way to get the xpath attribute of a webElement. Has anyone been able to do this?

I have an element and I want to get to its parent container to check it’s Acc ID. It’s for a case where my dev couldn’t get the Acc ID on the element itself, so it’s on the parent container. There are other ways to achieve my goal but they would be MUCH slower.

python 2.7.6
appium 1.3.4
xcode 6.1.1
ios 8.1

Ok I found the answer to my “parent” question on a Selenium board and did some more digging (I’m not great at xpath, so maybe this is just a known thing). But still I don’t know how to get the xpath of my element.

In [172]: driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIATableView/UIATableCell[2]/UIAStaticText').tag_name
Out[172]: u'UIAStaticText'

In [173]: driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIATableView/UIATableCell[2]/UIAStaticText/parent::*').tag_name
Out[173]: u'UIATableCell'

In [174]: driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIATableView/UIATableCell[2]/UIAStaticText/parent::*/parent::*').tag_name
Out[174]: u'UIATableView'

cool. also works with simple indexes:

In [175]: f.driver.find_element_by_xpath('//*[2]/*[1]/*[4]/*[2]/*[1]').tag_name
Out[175]: u'UIAStaticText'

In [176]: f.driver.find_element_by_xpath('//*[2]/*[1]/*[4]/*[2]/*[1]/parent::*').tag_name
Out[176]: u'UIATableCell'

What I found here though is that the xpath is being reported 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:

opened bug here.