【问题标题】:How to identify field with id in Appium using CodeceptJS?如何使用 CodeceptJS 在 Appium 中识别带有 id 的字段?
【发布时间】:2019-11-26 12:19:31
【问题描述】:

我正在尝试使用 CodeceptJS(它使用 Appium)来测试原生 Android 应用程序。我想使用方法 I.seeElement 来查看字段是否存在,但 Appium 服务器似乎只是挂起而没有错误消息。

此步骤是输入电话号码,以便用户登录。在此之前我可以单击一个按钮,但那是因为我能够使用简单的文本标识符。

这是我写的。 (I.click 方法在单击按钮时起作用。)


// in this file you can append custom step methods to 'I' object

module.exports = function() {
  return actor({

    login: function (I) {
        I.click('ALLOW');
        I.seeElement('#com.[package name removed]:id/phone');
    }

  });
}

这是错误信息:

[HTTP] --> POST /wd/hub/session/5e57e7af-ca1c-46bf-94ac-7e2f113a26fa/elements
[HTTP] {"using":"xpath","value":"//*[@resource-id='com.[package name removed]:id/phone']"}
[debug] [W3C (5e57e7af)] Calling AppiumDriver.findElements() with args: ["xpath","//*[@resource-id='com.[package name removed]:id/phone']","5e57e7af-ca1c-46bf-94ac-7e2f113a26fa"]
[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":"xpath","selector":"//*[@resource-id='com.[package name removed]:id/phone']","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@resource-id='com.[package name removed]:id/phone']","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[@resource-id='com.[package name removed]:id/phone']' using 'XPATH' with the contextId: '' multiple: true

【问题讨论】:

    标签: android xpath appium appium-android codeceptjs


    【解决方案1】:

    您可以像一些动态 id 示例一样使用智能选择器:

    'div[id$="test"] textarea'    //ends with id test
    '[id^='test']'      //start with id test
    

    您也可以使用智能定位器,请参阅 codeceptjs 定位器

    【讨论】:

    • 感谢您抽出宝贵时间回复,但这看起来像是测试网站的代码,我正在测试原生 Android 应用程序。我认为它在我最初的问题中并不明确,因此我将对其进行更新。
    【解决方案2】:

    使用您必须看到的元素的文本。 I.seeElement("~元素的文本")

    【讨论】:

    • 感谢您的回复,但这是一个字段。我意识到我应该在问题中指定这一点并对其进行更新。如果我理解正确,对于一个字段,没有文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2019-03-16
    • 1970-01-01
    • 2020-08-23
    相关资源
    最近更新 更多