using regular expression to identify elements with Appium

2,061 views
Skip to first unread message

Abhinav Mishra

unread,
Dec 12, 2013, 3:56:28 AM12/12/13
to appium-...@googlegroups.com
Hi,

I am trying to identify an element on app with regular expression. It is a tableview-cell containing (not matching) text 'Plpl1' (which is unique)
Please see the attachment for reference as seen in Appium-Inspector. Following are the two options I tried followed by the error displayed on Appium console

driver.find_element_by_xpath("//*[contains(.,'Plpl1')]")
driver.find_element_by_xpath("//cell[contains(text(), 'Plpl1')]")


info: Pushing command to appium work queue: "au.getElementsByXpath('\\/\\/*[contains(., \\'Plpl1\\')]')"

debug: Request received with params: {"using":"xpath","sessionId":"fd577d79-cfe2-4115-b8f4-122d2593999d","value":"//*[contains(., 'Plpl1')]"}
debug: Sending command to instruments: au.getElementsByXpath('\/\/*[contains(., \'Plpl1\')]')

info: [INSTSERVER] Sending command to instruments: au.getElementsByXpath('\/\/*[contains(., \'Plpl1\')]')

info: [INSTSERVER] Socket data received (219 bytes)


Please help me out with what I might be doing wrong here.
Thanks a ton.

:)
Abhinav

Abhinav Mishra

unread,
Dec 12, 2013, 4:12:14 AM12/12/13
to appium-...@googlegroups.com
Forgot attachment earlier. Here it is.


--
http://appium.io
---
You received this message because you are subscribed to a topic in the Google Groups "Appium-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appium-discuss/6z8Ih8EShRo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

AppInspector.png

Karthik Kulkarni

unread,
Dec 12, 2013, 4:19:26 AM12/12/13
to Abhinav Mishra, appium-...@googlegroups.com

I don't see the  inspector calling it xpath.it is just a label

You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.

Abhinav Mishra

unread,
Dec 12, 2013, 4:22:37 AM12/12/13
to Karthik Kulkarni, appium-discuss
The Details window is small to show all the details. Here it is 
=============

name: DevUser2, Plpl1, 11:44 am, Tr Sent from Acompli, 2

type: UIAStaticText

value: 

label: DevUser2, Plpl1, 11:44 am, Tr Sent from Acompli, 2

enabled: true

visible: true

valid: true

location: {0, 204}

size: {320, 96}

xpath: //window[1]/tableview[1]/cell[2]/text[1] 
===================================

Karthik Kulkarni

unread,
Dec 12, 2013, 4:36:36 AM12/12/13
to Abhinav Mishra, appium-discuss

/window[1]/tableview[1]/cell[2]/text

As far as I see there isno ppli in this . copy paste this xpath as is it should work

Abhinav Mishra

unread,
Dec 12, 2013, 4:42:55 AM12/12/13
to Karthik Kulkarni, appium-discuss
Hi Karthik

I am trying to identify an element based on the text it may contain. The xpath advised by you is correct but it identifies the text of second cell (via index) every time. I need to get an element which contains the text 'Plpl1' which may be at some other index. Please see the attachment in 2nd post. This is why I am trying to create an xpath with 'contains' clause which is failing at Appium call.

Thanks


Abhinav Mishra

unread,
Dec 12, 2013, 5:48:16 AM12/12/13
to Karthik Kulkarni, appium-discuss
Finally figured it out as

xpath=//text[contains(@name,'Plpl1')]
or
xpath=//cell[contains(@name,'Plpl1')]


Pooja Shah

unread,
Feb 18, 2014, 7:23:35 AM2/18/14
to appium-...@googlegroups.com, Karthik Kulkarni
Hi Abhinav,

I'm having similar situation where none of these working for chossing a date by its text in a calender. (PFA)

//text[contains(@name,'26')]
//text[contains(text(),'26')]
//TextView[@text='26’]
And according to Jonathan '*' implementation is not there yet so none of these works too  (/*[@text='27’] ,  /*[contains(@text,'27’)] , /*[contains(text(),'27’)])/*contains(@text,'27’)

Complete details are here- https://groups.google.com/forum/#!searchin/appium-discuss/Open$20up$20uiautomatorviewer$20and$20check$20the$20details$20of$20it$20there$2C$20that$20should$20help$20in$20figuring$20out$20how$20to$20access$20it/appium-discuss/gfSZavdRf-8/dLmDKHQkp8kJ


On RHS in image, I have added UiAutomatorViewer screenshot but it is showing different hierarchy and if I build xpath using it, it doesn't work too.
Then how to find such elements by text (Many times its needed to find an element by its text and then assertion on it)
Screen Shot 2014-02-18 at 5.35.43 pm.png
Reply all
Reply to author
Forward
0 new messages