Search code examples
androidviewandroid-uiautomator

Android Uiautomator not recognized the programatically view id


I have layout that I build using Java - not from XML file.

I'm assigning to each view an arbitrary id through the Java code:

For instance:

Button btn = new Button(this);
btn.setText("testBtn");
btn.setId(123456);

The problem is that the uiautomator, from the Android tools, is not recognize the id - I get empty id.

When I'm using XML file to add the button, all is working fine.

So my question is, what is the problem with the dynamically setting of the id, what are the changes between the two and why uiautomator isn't recognize the dynamically id?

P.S. Currently I prefer not the change all layouts to XML's


Solution

  • It's an UIAutomator limitiation.. UIAutomator only detects the objects listed in XML layouts