Struggling with getting new Appium xpath to work with 'contains'

528 views
Skip to first unread message

Curtis Siemens

unread,
Apr 23, 2014, 8:23:13 PM4/23/14
to appium-...@googlegroups.com
We are using python to drive our Appium testcases & I'm trying to convert them over to the new 1.0-beta appium real xpaths.

This used to work:
driver.find_element_by_xpath("//navigationBar/textfield[contains(@text, 'Enter Search Text')]")

With 1.0 I can get this to work:
driver.find_element_by_xpath("//UIANavigationBar/UIATextField[1]")
But that isn't as general - and the item might not always be the 1st textfield - I need contains to work in our xpaths.

I tried to get this to work (which is a simple translation from the shortcut xpath version), but so far no go:
driver.find_element_by_xpath("//UIANavigationBar/UIATextField[contains(@text, 'Enter Search Text')]")
- Always get back "status":7 "message":"An element count not be located on the page using the given search parameters."

bootstrap online

unread,
Apr 23, 2014, 8:24:58 PM4/23/14
to Curtis Siemens, appium-...@googlegroups.com
Does 'Enter Search Text' match exactly the text in the app? It may be
a mixed case issue.

Jonathan Lipps

unread,
Apr 23, 2014, 8:36:17 PM4/23/14
to bootstrap online, Curtis Siemens, appium-...@googlegroups.com
You might also try the @label and @name attributes. iOS does funny things with these sometimes. Failing that look at the source so you can see why your query is failing.

On Apr 23, 2014, at 5:24 PM, bootstrap online <ma...@bootstraponline.com> wrote:

> Does 'Enter Search Text' match exactly the text in the app? It may be
> a mixed case issue.
>
> --
> http://appium.io
> ---
> 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.
> Visit this group at http://groups.google.com/group/appium-discuss.
> For more options, visit https://groups.google.com/d/optout.

Curtis Siemens

unread,
Apr 24, 2014, 2:11:38 PM4/24/14
to appium-...@googlegroups.com
Thanks for the advice - turned out both replies were true:
1. The contains(@text, "aBc") is  case sensitive - so you have to have the right upper/lower case in your search to match the app.
2. The @text does not work (at least in iOS for our App), but @label does, so now this works: driver.find_element_by_xpath("//navigationBar/textfield[contains(@label, 'Enter Search Text')]")

Curtis Siemens

unread,
Apr 24, 2014, 2:13:54 PM4/24/14
to appium-...@googlegroups.com
Sorry I mean this now works:
driver.find_element_by_xpath("//UIANavigationBar/UIATextField[contains(@label, 'Enter Search Text')]")



--
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/SKmR4C_x2L0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.

bootstrap online

unread,
Apr 24, 2014, 2:15:43 PM4/24/14
to Curtis Siemens, appium-...@googlegroups.com
I have an example of case insensitive contains in the Ruby bindings.

https://github.com/appium/ruby_lib/blob/f4397302cc9ffc42759fe946e0da643df2c89100/lib/appium_lib/common/helper.rb#L173
> 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
Reply all
Reply to author
Forward
0 new messages