Find button by name

428 views
Skip to first unread message

ma...@bootstraponline.com

unread,
Feb 8, 2013, 5:45:56 PM2/8/13
to appium-...@googlegroups.com
I'm testing a native app with Appium. I can find all buttons.
@driver.find_elements :tag_name, :button

The only attribute that doesn't crash is name.
button.attribute :name

:class - crash
:class_name - crash
:css - crash
:id - crash
:link_text - crash
:link  - crash
:partial_link_text - crash 
:name - "Sign In"
:tag_name - crash
:xpath - crash

I can't find a specific button by name as mentioned in this thread. The result is always an empty array.
@driver.find_elements(:tag_name, 'button/Sign In')

Is the only way to find a specific button by checking the name attribute on every button?

bootstrap online

unread,
Feb 8, 2013, 6:01:53 PM2/8/13
to appium-...@googlegroups.com
I can see name, type, and label in @driver.page_source. find_element
only works with :name though.

[30] pry(main)> @driver.find_element :name, "Sign In"
=> #<Selenium::WebDriver::Element:0x..faf984c8e12b48416 id="0">

[31] pry(main)> @driver.find_element :type, "UIAButton"
ArgumentError: cannot find element by :type

[32] pry(main)> @driver.find_element :label, "Sign In"
ArgumentError: cannot find element by :label

Jonathan Lipps

unread,
Feb 8, 2013, 6:05:25 PM2/8/13
to bootstrap online, appium-...@googlegroups.com
I believe the two supported locator strategies are "tag name" and "name". We use a modified set of "tag names", based on mechanic.js, so this should work:

@driver.find_element :tag_name, "button"

And this (which you already discovered):

@driver.find_element :name, "Sign In"

This needs documentation.
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

bootstrap online

unread,
Feb 8, 2013, 6:13:10 PM2/8/13
to Jonathan Lipps, appium-...@googlegroups.com
Is there a way to use :tag_name to identify a specific button? It
seems to return any button. According to an old post, the :tag_name,
"button/Button Name" syntax use to work.

Jonathan Lipps

unread,
Feb 8, 2013, 6:36:59 PM2/8/13
to bootstrap online, appium-...@googlegroups.com
Hmm, that find-by-tag-name syntax isn't supported in this version of Appium. Which post are you referring to?

The way I would find a specific button right now is to find all the buttons using @driver.find_elements :tag_name, "button" and select the appropriate index to work on, or simply find the one element by :name if it is unique. (We encourage name to be unique, like an HTML id).

Selectors are a priority for expansion, but unfortunately UIAutomation isn't consistent in the properties it sets, and we found that "name" was the best candidate for finding individual unique elements, ideologically equivalent to @driver.find_element :id.

bootstrap online

unread,
Feb 8, 2013, 7:53:50 PM2/8/13
to Jonathan Lipps, appium-...@googlegroups.com
On Fri, Feb 8, 2013 at 6:36 PM, Jonathan Lipps <jli...@gmail.com> wrote:
> Hmm, that find-by-tag-name syntax isn't supported in this version of Appium. Which post are you referring to?

https://groups.google.com/forum/#!msg/appium-discuss/RwZAIwfglls/kQKlaPlLMXEJ

I think finding buttons by name will work.

Jonathan Lipps

unread,
Feb 11, 2013, 2:14:32 PM2/11/13
to bootstrap online, appium-...@googlegroups.com
Hmm, that custom "tagName/text" locator is quite different from Selenium protocol. If we re-implement something like that, I'd want to use the xpath strategy and do something like "//button[@name='Click me']" to conform more closely to the spec.

Anyone have thoughts on a what an xpath-like syntax could look like for UIAutomation?

Andrew Rymar

unread,
Aug 6, 2013, 3:22:59 PM8/6/13
to appium-...@googlegroups.com
Does anybody know how to find the element by it's classname? Not the generic UIButton, but some custom MyClassButton. Unfortunately, :tag_name doesn't work in that case.

Jonathan Lipps

unread,
Aug 6, 2013, 3:27:23 PM8/6/13
to Andrew Rymar, appium-...@googlegroups.com
Unfortunately I don't think Instruments allows you to look for custom element types.

On Aug 6, 2013, at 12:22 PM, Andrew Rymar <andrew...@gmail.com> wrote:

Does anybody know how to find the element by it's classname? Not the generic UIButton, but some custom MyClassButton. Unfortunately, :tag_name doesn't work in that case.

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.
Reply all
Reply to author
Forward
0 new messages