FindElementById works on Calculator app, not on our own app: is package:id necessary?

Hi,

my following code works on a generic Calculator app:

var driver = new AndroidDriver<AppiumWebElement>(server, options, TimeSpan.FromMinutes(2));
driver.FindElementById("bt_09").Click();
driver.FindElementById("com.sec.android.app.popupcalculator:id/bt_09").Click();

the same code does not work for our own app, but XPath does:

var driver = new AndroidDriver<AppiumWebElement>(server, options, TimeSpan.FromMinutes(2));
driver.FindElementById("at_loginButton").Click(); // fails
driver.FindElementByXPath("//android.widget.Button[@resource-id='at_loginButton']").Click(); // works

The only difference I can imagine, is that our app has no “package:id/” prefix to the resource-id, whereas the Calculator does.
Anyone has a clue?

In general the prefix is mandatory, although for the package under test it can be added automatically:

1 Like