android - 在 Android 中,使用 Webdriverio,如何通过资源 ID 选择元素?

标签 android automated-tests appium android-testing webdriver-io

我是 Appium 的新手,我想为我的 Android 应用程序创建一个测试,

使用设备监视器中的检查器,我找到了我的元素资源 ID:com.appPackage:id/categoryIconImageView。我像下面这样使用它。
而且我不知道为什么它不能正常工作?

const wdio = require("webdriverio");

const opts = {
  port: 4723,
  desiredCapabilities: {
    platformName: "Android",
    deviceName: "emulator-5556 device",
    udid: "emulator-5554",
    platformVersion: "8.0.0",
    appPackage: "com.appPackage",
    appActivity: "com.appActivity",
    appWaitActivity: "com.appWaitActivity",
    noReset: "true",
  }
};

const client = wdio.remote(opts);

var s= client.init().element("#com.appPackage:id/categoryIconImageView").click().end();

Appium日志
[HTTP] --> POST /wd/hub/session/028abf5e-43a7-44f6-ab27-9d49e56bab8e/element
[HTTP] {"using":"-android uiautomator","value":"new UiSelector().resourceId('com.opensooq.OpenSooq:id/categoryIconImageView')"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["-android uiautomator","new UiSelector().resourceId('com.opensooq.OpenSooq:id/categoryIconImageView')","028abf5e-43a7-44f6-ab27-9d49e56bab8e"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().resourceId('com.opensooq.OpenSooq:id/categoryIconImageView')","context":"","multiple":false}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 9 to UnknownCommandError
[HTTP] <-- POST /wd/hub/session/028abf5e-43a7-44f6-ab27-9d49e56bab8e/element 500 7 ms - 187

最佳答案

我正在使用 webdriver 版本 ^6.6.3我可以确认您可以使用:

client.$("id:resource-id-of-the-element");

关于android - 在 Android 中,使用 Webdriverio,如何通过资源 ID 选择元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733810/

相关文章:

javascript - 如何在 MAC 上使用 Protractor 与 Appium 和 IOS-Simulator 进行自动化测试

google-chrome - 无法调整在 headless Chrome 上运行 TestCafe 的窗口大小

security - Apache Jmeter 提取 __RequestVerificationToken 并使用它登录

java - 在 Appium 中使用 Xpath 查找元素的父元素

selenium - 如何在 kotlin 中使用 div 角色和 aria-label 设置 xpath

selenium - 机器人框架/ Selenium - 可以读取 javascript 控制台吗?

Android:在jetpack中使用线圈的图像的缓存有效性

javascript - 在 ParseInstallation 对象中包含用户名是不是一种不好的形式?

Android:来自 mysql 的新行字符在 textview 中不起作用

android - ionic 键盘事件未在 Android 上触发