Can't find element in android native app launched from another native app

Platform: Android
Android Version: 4.1.1
Appium Version: v1.4.16
Run on: Real Device
Language Used: java selendroid
OS: Linux-Ubuntu

Issue: Cannot able to find elements in one of the Native Application (‘say app2’) which was launched from another Native Application (‘say app1’).

Steps Followed:

  1. Using desired capabilities launched Activity1 of Application1: “com.pkg.ui.app1.activity1”,
  2. Navigated to a GridView to click on an Image View button to open Application2,
  3. Tried to find an element with id “btn1” in the Application2.

Code1 Tried:

try {
} catch (NoSuchElementException e) {
  System.out.println("->-> Not Found!!");

Code1 Log:

info: --> POST /wd/hub/session/f6b9df17-2448-6228-d782-eb5973508596/element {"using":"id","value":"btn1"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/f6b9df17-2448-6228-d782-eb5973508596/element","method":"POST","json":{"using":"id","value":"btn1"}}
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Element was not found."},"sessionId":"f6b9df17-2448-6228-d782-eb5973508596"}
info: <-- POST /wd/hub/session/f6b9df17-2448-6228-d782-eb5973508596/element 500 50139.518 ms - 201 

Code2 Tried:

try {
} catch (NoSuchElementException e) {
  System.out.println("->-> Not Found!!");

Code2 Log:

info: --> POST /wd/hub/session/57151ec0-235d-e164-feba-d6855c94bf9a/element {"using":"xpath","value":"//ImageView[@id='btn1']"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/57151ec0-235d-e164-feba-d6855c94bf9a/element","method":"POST","json":{"using":"xpath","value":"//ImageView[@id='btn1']"}}
info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"CATCH_ALL: io.selendroid.server.common.exceptions.SelendroidException: No open windows.\n\tat io.selendroid.server.model.internal.AbstractNativeElementContext.getElementTree(\n\tat io.selendroid.server.model.internal.AbstractNativeElementContext.findElementsByXPath(\n\tat io.selendroid.server.model.internal.AbstractNativeElementContext.findElementByXPath(\n\tat io.selendroid.server.model.internal.AbstractNativeElementContext.findElement(\n\tat io.selendroid.server.model.By$ByXPath.findElement(\n\tat io.selendroid.server.model.DefaultSelendroidDriver.findElement(\n\tat io.selendroid.server.handler.FindElement.safeHandle(\n\tat io.selendroid.server.handler.SafeRequestHandler.handle(\n\tat io.selendroid.server.AndroidServlet.handleRequest(\n\tat io.selendroid.server.common.BaseServlet.handleHttpRequest(\n\tat io.selendroid.server.common.http.ServerHandler.channelRead(\n\tat\n\tat\n\tat io.netty.handler.traffic.AbstractTrafficShapingHandler.channelRead(\n\tat\n\tat\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(\n\tat\n\tat\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(\n\tat\n\tat\n\tat\n\tat\n\tat$\n\tat\n\tat\n\tat\n\tat\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$\n\tat io.netty.util.concurrent.DefaultThreadFactory$\n\tat\n"},"sessionId":"57151ec0-235d-e164-feba-d6855c94bf9a"}
info: <-- POST /wd/hub/session/57151ec0-235d-e164-feba-d6855c94bf9a/element 500 79.744 ms - 3417


  1. Can able to access any element in the app1 without any issues, after navigating to app2 can’t able to access any element on this application.
  2. The button under discussion is inside a fragment.
  3. The id is taken from its fragment page layout xml file.

Please help me in resolve this…
Thanks in advance…


If I had this problem, I would dump page source and see what’s visible

You might find it more readable if you convert it with nokogiri:
page_source = Nokogiri::XML(appium_driver.get_source)

Check that the resource id exists in the view.


Thanks for your reply.

I suppose you are referring to a ruby method ‘appium_driver.get_source’ , but here I’m using java in my code.

Does this method work for a native application, if yes can you please point me to a java equivalent code.

Anyways, I have used both UIAutomatorViewer and searched in the xml layout of the activity page in the source code to verify the presence of the button, and seems it is available in the layout xml as well as can be viewable in UIAutomatorViewer (from where I have picked up the ID of the button to find the element).

Any other leads are more welcome…