Skip to main content

FAQ


Element Location Strategy  - 

Launch UIAutomationViewer as - 

uiautomatorviewer &

Following is an example for UIAutomationViewer and using it to find elements on Android App. Herein an image of UIAutomationViewer with calculator application - 



The Element 64 can be identified as - 
  • driver.findElement(By.name("64"));
  • driver.findElement(By.id("com.android.calculator2:id/formula"));
  • driver.findElement(By.className("android.widget.EditText"));
Element location by TagName is deprecated. Refer Stackoverflow post1 and post2 for more on this.
You can also use xPath strategy to identify element as described in this post.

Appium also supports Mobile JSON Wire Protocol locator strategy -


  • -ios uiautomation: a string corresponding to a recursive element search using the UIAutomation library (iOS-only)
  • -android uiautomator: a string corresponding to a recursive element search using the UiAutomator Api (Android-only)
  • accessibility id: a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize

Update chrome driver binaries -
At times chrome browser on real device may not work and can be fixed by updating chrome driver binaries which are downloaded by appium. download latest chrome driver binaries from -
And replace them in your appium download location, The location looks as following on my Ubuntu - /home/tarun/node-v0.12.2-linux-x64/lib/node_modules/appium/build/chromedriver/linux
Using Chrome browser on non rooted devices -
If you have a non rooted device then chrome would work for only version higher than 33, so if you using a version of chrome lower than 33.0 then upgrade it to higher version. This may be far easier than rooting the device :-) Moreover since chrome browser update automatically on Android hence you would like to test on latest version of chrome browser.
Killing a running instance of adb -


If you come across following error when executing tests -
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: /bin/sh -c /home/tarun/Documents/mine/lib/android-sdk-linux/platform-tools/adb -s adb server is out of date.  killing... wait-for-device ADB server didn't ACK * could not start server *)
then you may already have adb server up and running and you would have kill it. kill adb from command line as following -
killall -9 adb


How do I find the device version and name -
Couple of examples on other sites set VERSION and deviceName capabilities for android but appium seem to ignore it for android. Any way, these capabilities may be used by Appium in future and can be set as - 

capabilities.setCapability(CapabilityType.VERSION, “4.4”);
If your device is running 4.4.2 then VERSION is 4.4, if your device is running 5.1.1 then version is 5.1 and so on
With appium version 1.3.7 following message is logged in appium server which indicates that VERSION capability is anyway ignored by appium -

info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version
The deviceName capability can be set as - 

capabilities.setCapability(“deviceName”, “111bd508″);
The device name is found using adb command as - 
adb devices -l

List of devices attached 
emulator-5554          device product:sdk_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
Herein emulator-5554 is the deviceName

The deviceName capability is currently ignored for Android. Reference


Error: Unable to find an active device or emulator with OS 8.1. The following are available: emulator-5554 (7.1)
If you encounter this error then you need to specify PLATFORM_VERSION capability as following -

capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
I used version 7.1, use which ever version is applicable for your device

Popular posts from this blog

Return only first or last element from webelements collection

We often come across situation when there are multiple elements on a page and we probably like to exercise only a few of them using selenium webdriver. May be just first and last element. For example on a search result page we may like to click on only first and last link and not all. This is when Iterables API comes handy. (By the way I am assuming that you have already completed watching selenium training videos :)). Once we have collection of web element then we can use Iterables to get only first or last element as following - Consider that we fetch collection of element as - List< WebElement > webElements = getDriver().findElements(By. id ( "htmlID" ));   Now we can get the first web element from this collection as -  WebElement firstElement = Iterables. getFirst (webElements,  getDriver().findElement(By. id ( "defaultElement" )));   Herein second argument -   (getDriver().findElement(By. id ( "defaultElement" )))    in the me

Using chrome console to test xPath and css selectors

Since the advent of selenium there have been many plugin to test xPath / css selectors but you don’t need any of them if you have chrome browser. Using Chrome console you can test both xPath and css selectors. Launch website to be tested in chrome browser and hit F-12 and you would see chrome console opened in lower pane of application - Hit escape key and console would open another pane to write element locators - And now you can start writing xPath or css selectors in chrome console and test them - The syntax for writing css id - $$(“ ”) And hit the enter key. If your expression is right then html snippet of the application element corresponding to the css selector would be displayed - If you mouse over the html snippet in chrome console then it would highlight the corresponding element in application - If you want to clean console of previously written element selectors then just hit ctrl+L keys and chrome console would be empty again. Pro

Using xPath to reach parent of an element

Well, I am big fan of css locator my self there are times when css locators don't fit requirement. One such requirement is when you want to navigate to parent element of an element and may be parent of parent and even more. Unfortunately css locators don't provide any mechanism to navigate to parent of an element. See this for more. Of late I came across a scenario when I wanted to click on a link depending upon the text in a text box. Herein parent of text box and parent of link were at the same location. More over there could have been many such combinations in application. Fortunately I just need to pick first such instance and Web Driver any way considers only first instance when multiple locators are found matching an element. Element in question is in following html - Here I need to click on highlighted anchor on the basis of input element (which is also highlighted in image) Herein first I need to reach div parent (class = 'left couponmainarea