findElementByIosUIAutomation() And findElementByAndroidUIAutomator()

3,271 views
Skip to first unread message

Naidu A

unread,
Jun 2, 2014, 4:23:46 AM6/2/14
to appium-...@googlegroups.com
Hi,
From Appium 1.0.0, the below methods gets introduced.
I would like to know how to use below:
  • findElementByIosUIAutomation()
  • findElementsByIosUIAutomation()
  • findElementByAndroidUIAutomator()
  • findElementsByAndroidUIAutomator()
1) What are the advantages of the above methods?
2) How to use the above methods?


regards,
Naidu A S

Isaac Murchie

unread,
Jun 2, 2014, 12:17:47 PM6/2/14
to Naidu A, appium-...@googlegroups.com
These methods allow you to use commands from the underlying automation frameworks in order to find elements. So for Apple you can pass a String which will be executed as JavaScript in UIAutomation (https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/_index.html). For Android is runs as UIAutomator Java code (http://developer.android.com/tools/help/uiautomator/index.html)


--
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.

Jonathan Norman

unread,
Jun 3, 2014, 7:35:55 AM6/3/14
to appium-...@googlegroups.com, sunny...@gmail.com
What String should you pass for Apple?

Naidu A

unread,
Jun 3, 2014, 8:28:38 AM6/3/14
to appium-...@googlegroups.com, sunny...@gmail.com
If i am not wrong, we should pass "UIAButton" or "UIATextField"...etc.

eg: driver.findElementByIosUIAutomation("UIAButton")

Jonathan Norman

unread,
Jun 3, 2014, 9:41:24 AM6/3/14
to appium-...@googlegroups.com, sunny...@gmail.com
Do you have to do anything with your application code? Like you have to when you use AccessibilityID.
I don't see the reason of using findElementByIosUIAutomation if you have more than one button. What I want is something unique for every element

Regards,
Jonathan 

Isaac Murchie

unread,
Jun 3, 2014, 12:46:19 PM6/3/14
to Jonathan Norman, appium-...@googlegroups.com, Naidu A
You would pass UIAButton or UIATextField, etc., for findElementByClassName. For findElementsByIosUIAutomation you pass a string that is JavaScript for Apple's UIAutomation. So if you wanted the first text field, you could pass in "target.frontMostApp().mainWindow().textFields()[0]".

Fred

unread,
Jun 4, 2014, 4:24:08 PM6/4/14
to appium-...@googlegroups.com, jonathan.c...@gmail.com, sunny...@gmail.com
Hi Isaac..

Is FindElementByAndroidUIAutomator() even working on a real android device? I have tried loads of different combinations when constructing the UiSelector and they all fail.

do you have an example of one that is working? I think FindElementByAndroidUIAutomator might be busted. 

Appium server 1.1.0.0 AppiumDriver 0.3.0

-F

Isaac Murchie

unread,
Jun 4, 2014, 4:36:46 PM6/4/14
to Fred, appium-...@googlegroups.com, Jonathan Norman, Naidu A
For me, using the latest Appium from master, with the Python client 0.6, using A Moto E with Android 4.4.2 on it, can get a variety of commands to work

els = self.driver.find_elements_by_android_uiautomator("new UiSelector().clickable(true)")

els = self.driver.find_elements_by_android_uiautomator('new UiSelector().enabled(true)')

el = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.Button")')

What sort of things are you trying to do? 

Fred

unread,
Jun 4, 2014, 5:15:59 PM6/4/14
to appium-...@googlegroups.com, kclea...@pof.com, jonathan.c...@gmail.com, sunny...@gmail.com
I am doing something similar. 

There is a login button with a text label 'Login'.
it's class (from UI Automator app) is 'android.widget.Button'

I've tried 

       driver.FindElementByAndroidUIAutomator("new UiSelector().text(\"Login\")");
and
       driver.FindElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.Button[1]\")");  //there are two buttons on this screen
       driver.FindElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.Button\")");  

All attempts fail.  

Isaac Murchie

unread,
Jun 4, 2014, 7:32:38 PM6/4/14
to Fred, appium-...@googlegroups.com, Jonathan Norman, Naidu A
On a page with two android.widget.Button elements on it, 

els = self.driver.find_elements_by_android_uiautomator('new UiSelector().className("android.widget.Button").clickable(true)')

return two elements for me, both clickable.

However, selecting on the text of a Button seems not to work. It, however, seems to be an Android thing, because selecting on the text of other element types works fine.

el = self.driver.find_element_by_android_uiautomator('new UiSelector().checkable(true).text("OFF")')

Kevin Cleathero

unread,
Jun 4, 2014, 7:49:42 PM6/4/14
to Isaac Murchie, appium-...@googlegroups.com, Jonathan Norman, Naidu A
Curious, i did exactly what you did as follows...

     var els = driver.FindElementsByAndroidUIAutomator("new UiSelector().className(\"android.widget.Button\").clickable(true)");

And i get an {"Unexpected error. "} -> innerException = null  (same as every other attempt i have made)

Android version 4.4.2

Isaac Murchie

unread,
Jun 4, 2014, 7:51:25 PM6/4/14
to Kevin Cleathero, appium-...@googlegroups.com, Jonathan Norman, Naidu A
What language/client are you using?

Fred

unread,
Jun 6, 2014, 11:29:54 AM6/6/14
to appium-...@googlegroups.com, kclea...@pof.com, jonathan.c...@gmail.com, sunny...@gmail.com
C# with Appium version 1.1.0.0 and Appium driver 0.3.0

Vikas Chaudhary

unread,
Jun 13, 2014, 9:02:47 PM6/13/14
to appium-...@googlegroups.com, kclea...@pof.com, jonathan.c...@gmail.com, sunny...@gmail.com
Not working for me either. I am using Java  as language, I am using Appium 1.1.0 and java-client 1.2.1. Tried with following approaches, nonie of them worked.  

logger.debug(driver.findElement(MobileBy.AccessibilityId("Check Out")).isDisplayed());

//logger.debug(driver.findElement(MobileBy.IosUIAutomation("Check Out")).isEnabled());

//logger.debug(driver.findElement(MobileBy.IosUIAutomation("Check Out")).getAttribute("value"));

//logger.debug(driver.findElementByIosUIAutomation("Check Out").getText());

driver.findElementByIosUIAutomation("new UIAButton().name(\"Check Out\")").getText();


"Check Out" is the name of the button & and is visible in the page source. Using iOS 7 simulator. Please help if some one else faced this issue. I already tried switching to native or web view.

Isaac Murchie

unread,
Jun 13, 2014, 10:31:31 PM6/13/14
to Vikas Chaudhary, appium-...@googlegroups.com, Kevin Cleathero, Jonathan Norman, Naidu A
Are you sure that is valid UIAutomation code? It doesn't look like it to me.

I would expect something like 'buttons().withName("Check Out")'
Reply all
Reply to author
Forward
0 new messages