Problem in fetching child elements at specific position of all parent elements in IOS application using Xpath

I have following hierarchy in my native IOS application:

UIATableView

  • TableCell

    • UIATextView
    • UIATextField
    • UIATextField
  • TableCell

    • UIATextView
    • UIATextField
    • UIATextField

Now I want to write Xpath query which will fetch me the first child of each TableCell element using FindElementsByXpath()method.

I have written following xpath quey to achieve this:
//UIATableView/child::UIATableCell/child::[position()=1]
OR
//UIATableView/child::UIATableCell/child::[1]

both of these queries returning me only first element of first TableCell.
where as I want all the elements which are first child of each TableCell element.

Please help me in writing Xpath query to achieve this.

Thanks and Regards,
Pranoday

I think what you really want is:

find_elements_by_xpath("//UIATableView/UIATableCell/UIATextView[1]")

I believe that will give you a list of webdriver objects that include only the first TextView from within all of the available TableCells. No need to specify “child” since the XPATH is explicitly denoting the parent-child relationship.

I’m not saying this is the “best” solution, but the solution I personally chose was to compose a list of all UIATableCell using find_elements_by_xpath("//UIATableView/UIATableCell") which returns a list of webdriver objects, then iterate through that list to get whatever data I want from within the cells. I chose this method as each page in my app has a different amount/type of data within the cells. Iterating through the list gives me the opportunity to massage the data extracted into whatever format I need.

One challenge with Appium and XPATH is that you cannot currently find children of a known element using XPATH. But you can use find_element_by_class_name and other non-XPATH methods.

So you cannot:

cell = self.driver.find_element_by_xpath(<your_xpath>) text = cell.find_element_by_xpath(<your_xpath>) # This will fail

But you can:

cell = self.driver.find_element_by_xpath(<your_xpath>) text = cell.find_element_by_class_name(<your_class_name>) # UIATextView in your example

Hi Christopher,
Thanks for your response.I will check the xpath query you suggested in your reply i.e.find_elements_by_xpath("//UIATableView/UIATableCell/UIATextView[1]")
I know this should work,but let me confirm.

But 1 more thing,this xpath query will only work on UIAtextView objects,but I want to fetch first child of each of the TableCell irrespective of its type.

To achieve this how can I write xpath query?

Thing I want to achieve is:
First of all I am going to fetch the first children of all TableCells and then I am going to find out its type to decide on way to work with that object.

Please reply

Please

Hi Christopher,
I checked with following Xpath query you suggested:
//UIATableView/UIATableCell/UIATextView[1]

to get all first child UIATextView elements of all existing TableCell elements
but this is returning me only 1 UITextView element which is first child of my first TableCell element.

I have chekced this Xpath from Appium inspector and got the following log

{\rtf1\ansi\ansicpg1252\cocoartf1343\cocoasubrtf140
{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;\f1\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green255\blue0;
}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural

\f0\fs24 \cf2 \cb0 info\cf1 : --> POST /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/elements {“using”:“xpath”,“value”:"//UIATableView/UIATableCell/UIATextView[1]"}

\cf2 info\cf1 : [debug] Waiting up to 0ms for condition
\cf2 info\cf1 : [debug] Pushing command to appium work queue: “au.mainApp().getTreeForXML()”
\cf2 info\cf1 : [debug] Sending command to instruments: au.mainApp().getTreeForXML()
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:22 +0000 Debug: Got new command 7 from instruments: au.mainApp().getTreeForXML()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:22 +0000 Debug: evaluating au.mainApp().getTreeForXML()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:22 +0000 Debug: evaluation finished\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:22 +0000 Debug: responding with:alid":true,“visible”:true,“hint”:null,“path”:"/0/0",“x”:0,“y”:0,“width”:768,“height”:1024},">":[{“UIANavigationBar”:{"@":{“name”:“Controls”,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/0",“x”:-384,“y”:-32,“width”:768,“height”:64},">":[{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/0/0",“x”:-384,“y”:-32,“width”:768,“height”:64},">":[{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/0/0/0",“x”:-384,“y”:32,“width”:768,“height”:1},">":[]}}]}},{“UIAButton”:{"@":{“name”:“UINavigationBarBackIndicatorDefault.png”,“label”:“Back”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/0/1",“x”:-376,“y”:0,“width”:13,“height”:21},">":[]}},{“UIAButton”:{"@":{“name”:“Stop”,“label”:“Stop”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/0/2",“x”:-375,“y”:-6,“width”:40,“height”:30},">":[]}},{“UIAStaticText”:{"@":{“name”:“Controls”,“label”:“Controls”,“value”:“Controls”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/0/3",“x”:-33,“y”:-4,“width”:67,“height”:27},">":[]}}]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/1",“x”:0,“y”:0,“width”:768,“height”:1024},">":[]}},{“UIAScrollView”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2",“x”:0,“y”:0,“width”:768,“height”:1024},">":[{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/0",“x”:0,“y”:0,“width”:768,“height”:968},">":[]}},{“UIAScrollView”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1",“x”:0,“y”:0,“width”:768,“height”:968},">":[{“UIATableView”:{"@":{“name”:null,“label”:null,“value”:“rows 1 to 3 of 3”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0",“x”:35,“y”:101,“width”:412,“height”:333},">":[{“UIATableGroup”:{"@":{“name”:“Alpha”,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/0",“x”:35,“y”:101,“width”:412,“height”:33},">":[{“UIAButton”:{"@":{“name”:“Alpha”,“label”:“Alpha”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/0/0",“x”:35,“y”:101,“width”:221,“height”:33},">":[]}},{“UIAButton”:{"@":{“name”:“Num”,“label”:“Num”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/0/1",“x”:256,“y”:101,“width”:127,“height”:33},">":[]}},{“UIAButton”:{"@":{“name”:“Date”,“label”:“Date”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/0/2",“x”:383,“y”:101,“width”:146,“height”:33},">":[]}},{“UIAButton”:{"@":{“name”:“Time”,“label”:“Time”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/0/3",“x”:529,“y”:101,“width”:117,“height”:33},">":[]}}]}},{“UIATableCell”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/1",“x”:35,"
y":134,“width”:412,“height”:33},">":[{“UIATextView”:{"@":{“name”:null,“label”:null,“value”:“SDSD”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/1/0",“x”:44,“y”:141,“width”:130,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“1”,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/1/1",“x”:265,“y”:150,“width”:113,“height”:17},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“01/01/1901”,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/1/2",“x”:392,“y”:141,“width”:131,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“00:00:00”,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/1/3",“x”:538,“y”:141,“width”:102,“height”:26},">":[]}}]}},{“UIATableCell”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/2",“x”:35,“y”:167,“width”:412,“height”:33},">":[{“UIATextView”:{"@":{“name”:null,“label”:null,“value”:“DF”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/2/0",“x”:44,“y”:174,“width”:130,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“2”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/2/1",“x”:265,“y”:183,“width”:113,“height”:17},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“01/01/1901”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/2/2",“x”:392,“y”:174,“width”:131,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“00:00:00”,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/2/3",“x”:538,“y”:174,“width”:102,“height”:26},">":[]}}]}},{“UIATableCell”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/3",“x”:35,“y”:200,“width”:412,“height”:33},">":[{“UIATextView”:{"@":{“name”:null,“label”:null,“value”:“DFDF”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/3/0",“x”:44,“y”:207,“width”:130,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“3”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/3/1",“x”:265,“y”:216,“width”:113,“height”:17},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“01/01/1901”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/0/3/2",“x”:392,“y”:207,“width”:131,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:“00:00:00”,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/0/3/3",“x”:538,“y”:207,“width”:102,“height”:26},">":[]}}]}}]}},{“UIAStaticText”:{"@":{“name”:“Text”,“label”:“Text”,“value”:“Text”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/1",“x”:266,“y”:345,“width”:206,“height”:43},">":[]}},{“UIAScrollView”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/2",“x”:417,“y”:354,“width”:299,“height”:119},">":[{“UIAStaticText”:{"@":{“name”:“Group”,“label”:“Group”,“value”:“Group”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/2/0",“x”:417,“y”:354,“width”:299,“height”:22},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/2/1",“x”:417,“y”:354,“width”:299,“height”:119},">":[]}},{“UIAButton”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/2/2",“x”:427,“y”:388,“width”:118,“height”:32},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/2/3",“x”:709,“y”:468,“width”:7,“height”:5},">":[]}},{“UIAImage”:{"@":{“name”:null,"labe
\f1 \cf0 \cb1 \

\f0 \cf3 \cb0 l":null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/2/4",“x”:711,“y”:466,“width”:5,“height”:7},">":[]}}]}},{“UIASwitch”:{"@":{“name”:null,“label”:null,“value”:0,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/3",“x”:249,“y”:434.5,“width”:51,“height”:31},">":[]}},{“UIAStaticText”:{"@":{“name”:“True,False”,“label”:“True,False”,“value”:“True,False”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/4",“x”:300,“y”:433,“width”:107,“height”:34},">":[]}},{“UIAButton”:{"@":{“name”:null,“label”:null,"\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] value":null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/5",“x”:280,“y”:503,“width”:69,“height”:39},">":[]}},{“UIAStaticText”:{"@":{“name”:“Enable”,“label”:“Enable”,“value”:“Enable”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/6",“x”:35,“y”:569,“width”:60,“height”:26},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:false,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/7",“x”:103,“y”:569,“width”:129,“height”:34},">":[]}},{“UIAStaticText”:{"@":{“name”:“Visible”,“label”:“Visible”,“value”:“Visible”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/8",“x”:27,“y”:653,“width”:54,“height”:23},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/9",“x”:90,“y”:653,“width”:130,“height”:32},">":[]}},{“UIAScrollView”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/10",“x”:417,“y”:586,“width”:250,“height”:240},">":[{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/10/0",“x”:417,“y”:586,“width”:250,“height”:240},">":[]}},{“UIAStaticText”:{"@":{“name”:“S1:”,“label”:“S1:”,“value”:“S1:”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/10/1",“x”:425,“y”:608,“width”:31,“height”:25},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/10/2",“x”:464,“y”:608,“width”:129,“height”:34},">":[]}},{“UIAStaticText”:{"@":{“name”:“S2:”,“label”:“S2:”,“value”:“S2:”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/10/3",“x”:425,“y”:664,“width”:31,“height”:23},">":[]}},{“UIATextField”:{"@":{“name”:null,“label”:null,“value”:"",“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/1/10/4",“x”:464,“y”:664,“width”:129,“height”:32},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/10/5",“x”:660,“y”:821,“width”:7,“height”:5},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/10/6",“x”:662,“y”:819,“width”:5,“height”:7},">":[]}}]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/11",“x”:9,“y”:719,“width”:18,“height”:218},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/12",“x”:761,“y”:1027,“width”:7,“height”:5},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/1/13",“x”:763,“y”:1025,“width”:5,“height”:7},">":[]}}]}},{“UIATabBar”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/2",“x”:0,“y”:968,“width”:768,“height”:56},">":[{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/2/0
“,“x”:0,“y”:967,“width”:768,“height”:1},”>":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/2/1",“x”:0,“y”:968,“width”:768,“height”:56},">":[]}},{“UIAButton”:{"@":{“name”:"‘Tab1",“label”:"‘Tab1",“value”:1,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/2/2",“x”:291,“y”:969,“width”:76,“height”:55},">":[]}},{“UIAButton”:{"@":{“name”:"Tab2’",“label”:"Tab2’",“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/2/2/3",“x”:401,“y”:969,“width”:76,“height”:55},">":[]}}]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/3",“x”:761,“y”:1019,“width”:7,“height”:5},">":[]}},{“UIAImage”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:false,“hint”:null,“path”:"/0/0/2/4",“x”:763,“y”:1017,“width”:5,“height”:7},">":[]}}]}}]}},{“UIAWindow”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/1",“x”:0,“y”:0,“width”:768,“height”:1024},">":[{“UIAStatusBar”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/1/0",“x”:0,“y”:0,“width”:768,“height”:20},">":[{“UIAElement”:{"@":{“name”:“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top”,“label”:null,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top”,“path”:"/0/1/0/0",“x”:6,“y”:0,“width”:39,“height”:20},">":[]}},{“UIAElement”:{"@":{“name”:“3 of 3 Wi-Fi bars”,“label”:“3 of 3 Wi-Fi bars”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top”,“path”:"/0/1/0/1",“x”:50,“y”:0,“width”:13,“height”:20},">":[]}},{“UIAElement”:{"@":{“name”:“11:20 AM”,“label”:“11:20 AM”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top”,“path”:"/0/1/0/2",“x”:359,“y”:0,“width”:51,“height”:20},">":[]}},{“UIAElement”:{"@":{“name”:“100% battery power”,“label”:“100% battery power”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top”,“path”:"/0/1/0/3",“x”:704,“y”:0,“width”:59,“height”:20},">":[]}}]}}]}}]}}}\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:22 +0000 Debug: Running system command #8: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“UIAApplication”:{"@":{“name”:“uniPaaS”,“label”:“uniPaaS”,“value”:null,“dom”:n…\cf1
\cf2 info\cf1 : [debug] Socket data received (8192 bytes)
\cf2 info\cf1 : [debug] Socket data received (6656 bytes)
\cf2 info\cf1 : [debug] Socket data being routed.
\cf2 info\cf1 : [debug] Got result from instruments: {“status”:0,“value”:{“UIAApplication”:{"@":{“name”:“uniPaaS”,“label”:“uniPaaS”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0",“x”:0,“y”:20,“width”:768,“height”:1004},">":[{“UIAWindow”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,“v
\cf2 info\cf1 : [debug] Pushing command to appium work queue: “au.getElementsByIndexPaths([\”/0/0/2/1/0/1/0\”])"
\cf2 info\cf1 : [debug] Sending command to instruments: au.getElementsByIndexPaths(["/
0/0/2/1/0/1/0"])
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:23 +0000 Debug: Got new command 8 from instruments: au.getElementsByIndexPaths(["/0/0/2/1/0/1/0"])\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:23 +0000 Debug: evaluating au.getElementsByIndexPaths(["/0/0/2/1/0/1/0"])\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:23 +0000 Debug: evaluation finished\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:23 +0000 Debug: responding with:\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:23 +0000 Debug: Running system command #9: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:[{“ELEMENT”:“0”}]}…\cf1
\cf2 info\cf1 : [debug] Socket data received (40 bytes)
\cf2 info\cf1 : [debug] Socket data being routed.
\cf2 info\cf1 : [debug] Got result from instruments: {“status”:0,“value”:[{“ELEMENT”:“0”}]}
\cf2 info\cf1 : [debug] Responding to client with success: {“status”:0,“value”:[{“ELEMENT”:“0”}],“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : <-- POST /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/elements \cf3 200\cf1 2276.982 ms - 89 {“status”:0,“value”:[{“ELEMENT”:“0”}],“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : --> GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/location {}
\cf4 warn\cf1 : location will be removed in a future version of Appium, please use location_in_view
\cf2 info\cf1 : [debug] Pushing command to appium work queue: “au.getElement(‘0’).getElementLocation()”
\cf2 info\cf1 : [debug] Sending command to instruments: au.getElement(‘0’).getElementLocation()
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:24 +0000 Debug: Got new command 9 from instruments: au.getElement(‘0’).getElementLocation()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:24 +0000 Debug: evaluating au.getElement(‘0’).getElementLocation()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:24 +0000 Debug: evaluation finished\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:24 +0000 Debug: responding with:\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:24 +0000 Debug: Running system command #10: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“x”:44,“y”:141}}…\cf1
\cf2 info\cf1 : [debug] Socket data received (39 bytes)
\cf2 info\cf1 : [debug] Socket data being routed.
\cf2 info\cf1 : [debug] Got result from instruments: {“status”:0,“value”:{“x”:44,“y”:141}}
\cf2 info\cf1 : [debug] Responding to client with success: {“status”:0,“value”:{“x”:44,“y”:141},“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : <-- GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/location \cf3 200\cf1 1009.567 ms - 88 {“status”:0,“value”:{“x”:44,“y”:141},“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : --> GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/size {}
\cf2 info\cf1 : [debug] Pushing command to appium work queue: “au.getElement(‘0’).getElementSize()”
\cf2 info\cf1 : [debug] Sending command to instruments: au.getElement(‘0’).getElementSize()
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:25 +0000 Debug: Got new command 10 from instruments: au.getElement(‘0’).getElementSize()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:25 +0000 Debug: evaluating au.getElement(‘0’).getElementSize()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:25 +0000 Debug: evaluation finished\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:25 +0000 Debug: responding with:\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:25 +0000
Debug: Running system command #11: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“width”:130,“height”:26}}…\cf1
\cf2 info\cf1 : [debug] Socket data received (48 bytes)
\cf2 info\cf1 : [debug] Socket data being routed.
\cf2 info\cf1 : [debug] Got result from instruments: {“status”:0,“value”:{“width”:130,“height”:26}}
\cf2 info\cf1 : [debug] Responding to client with success: {“status”:0,“value”:{“width”:130,“height”:26},“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : <-- GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/size \cf3 200\cf1 1001.806 ms - 97 {“status”:0,“value”:{“width”:130,“height”:26},“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : --> GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/name {}
\cf2 info\cf1 : [debug] Pushing command to appium work queue: “au.getElement(‘0’).type()”
\cf2 info\cf1 : [debug] Sending command to instruments: au.getElement(‘0’).type()
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:26 +0000 Debug: Got new command 11 from instruments: au.getElement(‘0’).type()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:26 +0000 Debug: evaluating au.getElement(‘0’).type()\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:26 +0000 Debug: evaluation finished\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:26 +0000 Debug: responding with:\cf1
\cf2 info\cf1 : [debug] \cf3 [INST] 2015-06-28 05:50:26 +0000 Debug: Running system command #12: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:“UIATextView”}…\cf1
\cf2 info\cf1 : [debug] Socket data received (36 bytes)
\cf2 info\cf1 : [debug] Socket data being routed.
\cf2 info\cf1 : [debug] Got result from instruments: {“status”:0,“value”:“UIATextView”}
\cf2 info\cf1 : [debug] Responding to client with success: {“status”:0,“value”:“UIATextView”,“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}
\cf2 info\cf1 : <-- GET /wd/hub/session/5159a2b6-c6b3-4058-85a8-7be9bcf61bb8/element/0/name \cf3 200\cf1 998.873 ms - 85 {“status”:0,“value”:“UIATextView”,“sessionId”:“5159a2b6-c6b3-4058-85a8-7be9bcf61bb8”}}

I think this is the bug in Appium.

Please go through below my research and correct me if I am wrong.

Please see the way Appium is translating this Xpath query before sending it to IOSUiaAutomation:
au.getElementsByIndexPaths(["/\0/0/2/1/0/1/0"])\

If we specify any index in Xpath Query then translated Index path will not contain a list of Index paths.

If I write my Xpath query as ://UIATableView/UIATableCell/UIATextView

then this will be translated as
“au.getElementsByIndexPaths([\”/0/0/2/1/0/1/0\",\"/0/0/2/1/0/2/0\",\"/0/0/2/1/0/3/0\"])"
}

so it seems that when we dont specify any index in xpath, then translated Index path contains list of Index paths which makes Appium to return elements at specified index from all parents.

but list of Index paths should be generated eventhough my xpath query contains index at the end (e.g.//UIATableView/TableCell/UIATextView[1]) to be able to get all UITextView elements which are first child of all TableCell elements.

Please help in resolving this.

Thanks and Regards,
Pranoday

Make sure you are calling find_elements plural vs find_element singular. The former will always return a list (an empty list if nothing found), the latter will only return a single result even if there are many or an exception if none are found.

As far as simply wanting to get the first child element of ANY type, then use a wildcard:

driver.find_elements_by_xpath("//UIATableView/UIATableCell/*[1]")

That should return a list of the first child element of each UIATableCell.

Note I haven’t tested any of this. I’m just freely typing it based on what I believe should work. But xpath on iOS is very reliable from my experience. I based my entire framework on xpath. I frequently use this XPATH tester which is great: http://www.freeformatter.com/xpath-tester.html You enter your XML which you can copy from the Appium Inspector, then enter your xpath which in this case would be //UIATableView/UIATableCell/*[1] and it will list the results which should match exactly what Appium provides.

@Christopher_Graham
Thanks Christopher for replying.

Xpath query you suggested is absolutely correct but the problem occurs when we submit it to Appium IOS server,it does not translate it in correct IndexPaths before submitting it to IOSuiautomation.

If we take the pagesource in xml form and run the xpath query which you have suggested above on that xml it works as expected. and returns the expected result.

I have implemented my solution successfully by taking the pagesource and have xpath queries run on that generated xml.

But this seems to be problem with Appium IOS server though.

If you want you can also check the result by pasting your query in IOS appium inspector.

Thanks and Regards,
Pranoday

Make sure you have the latest Appium installed and if you think you’ve found a bug do like us QA people do every day of our professional careers:

  1. Search the bug reports to see if your issue has already been filed.
  2. Log a new bug if one doesn’t exist.

You can access the Appium bug reports on Git here: https://github.com/appium/appium/issues

@Christopher_Graham
Yes I have latest Appium i.e. 1.4.0

I will check for the existence of issue and will report it otherwise on the given link as you suggested.

Thanks,
Pranoday

Hey @Pranodayd did you end up opening a bug report for this? I’m seeing it with appium 1.4.14

Hi @nicolasavenza .Sorry I have not opened a bug because I solved this problem for us by changing our implementation.If you can file it,that will be great help for all of us.

Thanks and Regards,
Pranoday

Hello guys,
I`m also encountering this issue, do you know if this issue was submitted eventually ?

Hi @Testerescu
I have not entered this bug as we solved this problem by getting pagesource and then parsing .xml file using xpath.You can enter this bug https://github.com/appium/appium/issues

Thanks and Regards,
Pranoday

Hello,

I will submit the bug, but until then i have found a way to work around this.
So if you are attempting to get the list of all child elements at fix position from a parent that has varying index, you can use :

It should work normally like this : [FindsByIOSUIAutomation(XPath = “//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell/UIAStaticText[1]”, Priority = 1)]

See the UIATableCell is the parent which is dynamic in my list, going all the way to 100+ table cells but the element within it that i want to put in a list is always static, at index [1] (UIAStaticText). Appium at the moment recognizes only the first such element although most xpath validators see the above expression correctly and give the full list of elements.

I worked around it like this : [FindsByIOSUIAutomation(XPath = “//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[position()>=1]/UIAStaticText[position()>=1][position() mod 2=0]”, Priority = 1)]

Now it searches in all UIATableCells and does not stop at the first one.
As a temporary workaround it should work for most people.

Cheers.

Hello guys.
I have reported the bug for the problem discussed in this post on Github.
Please use bug number #6227 to track the progress of the same.

Thank you all.

Regards,
Pranoday