Android - Not Finding Element?

Hi everyone,

I am having some trouble finding an element on the screen and generally I think the logs are telling me everything but sometimes I feel like I need a tutorial on deciphering them.
Based on the code snippet below, does this mean its not finding the element at all?

[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.widget.Button[@text=‘Log Me Out’]”,“context”:“”,“multiple”:true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.widget.Button[@text=‘Log Me Out’]”,“context”:“”,“multiple”:true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.Button[@text=‘Log Me Out’]’ using ‘XPATH’ with the contextId: ‘’ multiple: true
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.Button[@text=‘Log Me Out’]’ using ‘XPATH’ with the contextId: ‘’ multiple: true
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElements() result:

Whats confusing here to me is if I have it print the elements text value, it is able to do so successfully so I am not sure how it could do that if its not finding the element.


The last log output shows your findElements() returned an empty array. How are you printing the text of the elements value?

@brian-themaven I am using a simple println() statement to print the contents of what it finds.
It seems to be printing just 1 value fine.

I have been digging into this a bit more and it appears that because of the XML structure its taking a very very long time to search it for the element I am looking for. I had to up my timeout values for assertion considerably to figure this out.

    okButton(wait: true) { $(By.xpath("//android.widget.Button[@resource-id='com.test.leadcap:id/logOutButton']")) }

Not sure why it takes quite that long to search all the paths, I would estimate its taking around 10 min to find the element.

I’ve seen the long search times too. I’ve added this to the my android capabilities setCapability(‘compressXml’, ‘true’); It seems to help. Also I’ve found searching by classnames and ids seems to faster than xpath but sometimes still struggle to get them right.

@brian-themaven Do you happen to have an example of how exactly you are searching via classname and ids?
I have tried some combos of this but not much success.

I will also try implementing the compressXML capability and see if that helps.

Here’s a link that has some good examples.

Perfect. I will give that a look over.

Thx again for the help.