UiAutomator2 can find element; Espresso can't.
See original GitHub issueThe problem
With UiAutomator2, I am able to find an element by xpath. Once I switch to using Espresso, however, it gets stuck trying to find the same element.
Environment
- Appium version (or git revision) that exhibits the issue: 1.15.1
- Last Appium version that did not exhibit the issue (if applicable):
- Desktop OS/version used to run Appium: macOS Mojave - 10.14.6
- Node.js version (unless using Appium.app|exe): 12.13.1
- Npm or Yarn package manager: yarn 1.16.0
- Mobile platform/version under test: Android 9
- Real device or emulator/simulator: emulator
- Appium CLI or Appium.app|exe: Appium CLI
Details
When spying on elements via Appium Studio, I can get xpaths just fine. UiAutomator2 can then detect elements using those xpaths, but Espresso can’t. When I use an xpath as a selector such as const environment = await driver.$("//*[@tag='Primary_Button_Login']");
, it just hangs there, waiting to find it. It also hangs when I use this selector strategy: driver.$("~Primary_Button_Login")
. Espresso can’t seem to see anything.
Here are my capabilities:
capabilities: {
platformName: "Android",
platformVersion: "9",
deviceName: "Android Phone",
app: "/Users/blane/Documents/Development/appium/[AppNameRedacted].apk",
appPackage: "com.[AppNameRedacted].mobile.enterprise",
appActivity: "com.[AppNameRedacted].mobile.MainActivity",
automationName: "Espresso",
forceEspressoRebuild: "true",
newCommandTimeout: 10,
appWaitDuration: 60000,
autoGrantPermissions: "true"
}
Link to Appium logs
Source code of test
"use strict"
const wdio = require("webdriverio");
jest.setTimeout(100000);
// Android testing for emulator and device.
const opts = {
port: 4723,
capabilities: {
platformName: "Android",
platformVersion: "9",
deviceName: "Android Phone",
app: "/Users/blane/Documents/Development/appium/[AppNameRedacted].apk",
appPackage: "com.[AppNameRedacted].mobile.enterprise",
appActivity: "com.[AppNameRedacted].mobile.MainActivity",
// automationName: "UiAutomator2",
automationName: "Espresso",
forceEspressoRebuild: "true",
newCommandTimeout: 10,
appWaitDuration: 60000,
autoGrantPermissions: "true",
clearDeviceLogsOnStart: "true"
}
};
it('should show login screen using Espresso driver', async () => {
const driver = await wdio.remote(opts);
await driver.setImplicitTimeout(30000);
// const environment = await driver.$("//*[@tag='Midway (Local Proxy)']");
// const environment = await driver.$("//*[@text='Midway (Local Proxy)']");
// Test flow hangs at next line.
const environment = await driver.$("~Midway (Local Proxy)");
await environment.touchAction('tap');
const logIn = await driver.$("//*[@text='LOG IN']");
// const logIn = await driver.$("//*[@tag='PrimaryButton_Login']");
await logIn.touchAction('tap');
const username = await driver.$("//*[@text='Card User ID']");
await username.addValue("ASYS12345");
const password = await driver.$("//*[@text='Password']");
await password.addValue("Discover01");
const loginButton = await driver.$("//*[@text='LOG IN']");
await loginButton.touchAction('tap');
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Could not find element with strategy XPATH and selector ...
Can anyone help me? I am using Appium 1.18.0-beta.0 Serenity 1.9.45. appium · android-espresso · appium- ...
Read more >How to locate element using UIAutomatorViewer - BrowserStack
UI Elements can be defined by ID, ClassName, Name, Accessibility ID, XPath in Appium. To understand how to inspect or locate a UI...
Read more >UIAutomator2 (Android) - Appium
With this tool, create the emulator that matches your needs. With the emulator launched, Appium will automatically find and use it for its...
Read more >Chapter-4: Appium Locator Finding Strategies - Kobiton
After all, if you're unable to “find” the UI element, you cannot control it (such as clicking a button). ... Android UiAutomator (UiAutomator2...
Read more >Espresso vs UI Automator - Medium
We find out what the Espresso and UI Automator are. ... Ui Object can reuses for different views, but Ui Object 2 can't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
“Should” is a loaded word here. What is actually seen by Espresso is important. Can you get the source, in your test script, right before you are trying to find the element?
Closed as not an issue