当前位置: 首页 > 知识库问答 >
问题:

两个Appium选择器,其中只有一个接受文本

呼延升
2023-03-14
const login_field = await driver.$('android=new UiSelector().resourceId("my.fancy.app:id/input_login_email")');
await login_field.setValue("12345678");

这不起作用(找到元素,然后抛出“login_field.setvalue不是函数”):

const login_field = await driver.findElement("id", "my.fancy.app:id/input_login_email");
await login_field.setValue("12345678");

我对这两种策略进行了一些跟踪:

id(控制台日志):

[0-0] 2019-08-05T06:49:03.157Z INFO webdriver: COMMAND findElement("id", "my.fancy.app:id/input_login_email")
[0-0] 2019-08-05T06:49:03.158Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element
[0-0] 2019-08-05T06:49:03.158Z INFO webdriver: DATA { using: 'id', value: 'my.fancy.app:id/input_login_email' }
[0-0] 2019-08-05T06:49:11.577Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '7fe8b296-0ea5-4ffb-9450-12245de54bfa',
  ELEMENT: '7fe8b296-0ea5-4ffb-9450-12245de54bfa' }

Appium服务器:

[HTTP] --> POST /wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element
[HTTP] {"using":"id","value":"my.fancy.app:id/input_login_email"}
[debug] [W3C (6357f0a4)] Calling AppiumDriver.findElement() with args: ["id","my.fancy.app:id/input_login_email","6357f0a4-ecc2-4e45-be55-c16a6ccfedcb"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/85f9a408-10f4-41dc-8a26-27f7ec98f874/element] with body: {"strategy":"id","selector":"my.fancy.app:id/input_login_email","context":"","multiple":false}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"85f9a408-10f4-41dc-8a26-27f7ec98f874","status":0,"value":{"ELEMENT":"7fe8b296-0ea5-4ffb-9450-12245de54bfa"}}
[debug] [W3C (6357f0a4)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"7fe8b296-0ea5-4ffb-9450-12245de54bfa","ELEMENT":"7fe8b296-0ea5-4ffb-9450-12245de54bfa"}
[HTTP] <-- POST /wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element 200 8407 ms - 137
[0-0] 2019-08-05T06:49:11.579Z INFO webdriver: COMMAND findElement("-android uiautomator", "new UiSelector().resourceId("my.fancy.app:id/input_login_email")")
[0-0] 2019-08-05T06:49:11.580Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element
[0-0] 2019-08-05T06:49:11.580Z INFO webdriver: DATA { using: '-android uiautomator',
  value:
   'new UiSelector().resourceId("my.fancy.app:id/input_login_email")' }
[0-0] 2019-08-05T06:49:11.776Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '88ee4e4f-e3dd-4068-91d6-c26860e538b4',
  ELEMENT: '88ee4e4f-e3dd-4068-91d6-c26860e538b4' }
[HTTP] --> POST /wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element
[HTTP] {"using":"-android uiautomator","value":"new UiSelector().resourceId(\"my.fancy.app:id/input_login_email\")"}
[debug] [W3C (6357f0a4)] Calling AppiumDriver.findElement() with args: ["-android uiautomator","new UiSelector().resourceId(\"my.fancy.app:id/input_login_email\")","6357f0a4-ecc2-4e45-be55-c16a6ccfedcb"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/85f9a408-10f4-41dc-8a26-27f7ec98f874/element] with body: {"strategy":"-android uiautomator","selector":"new UiSelector().resourceId(\"my.fancy.app:id/input_login_email\")","context":"","multiple":false}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"85f9a408-10f4-41dc-8a26-27f7ec98f874","status":0,"value":{"ELEMENT":"88ee4e4f-e3dd-4068-91d6-c26860e538b4"}}
[debug] [W3C (6357f0a4)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"88ee4e4f-e3dd-4068-91d6-c26860e538b4","ELEMENT":"88ee4e4f-e3dd-4068-91d6-c26860e538b4"}
[HTTP] <-- POST /wd/hub/session/6357f0a4-ecc2-4e45-be55-c16a6ccfedcb/element 200 194 ms - 137
    null
  • 7Fe8B296-0EA5-4FFB-9450-12245DE54BFA
  • 88EE4E4F-E3DD-4068-91D6-C26860E538B4

但我认为这是因为这些ID是动态分配给使用Appium找到的元素的。

我还尝试在键入textbox之前单击该元素-不,则无法单击textbox(使用id策略):

const toast = await driver.findElement("xpath", "//android.widget.Toast[1]");
toast.text => undefined

toast.getAttribute("name") => "toast.getAttribute is not a function"

共有1个答案

羊舌高明
2023-03-14

我花了一些时间研究文档和其他网页,并提出了以下解决方案:

const login_field2 = await driver.findElement("id", "my.fancy.app:id/input_login_email");
await driver.setValueImmediate(login_field2.ELEMENT, "12345678");

这是一个更好的解决方案,因为您可以使用不同的选择器策略(包括XPath!):

[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator

然而,我仍然需要找到一种方法来提取我找到的元素的其他属性,例如toast通知文本...

const login_field = await driver.$('id=my.fancy.app:id/input_login_email');
await login_field.setValue("99999999");

>

  • 硒远程(?)道:

    Driver.findElement()

    WebdriverIO道:

    const toast = await driver.findElement("xpath", "//android.widget.Toast[1]");
    const toastText = await driver.getElementAttribute(toast.ELEMENT, "text")
    expect(toastText).to.equal("Toast text")
    
    COMMAND findElement("xpath", ".//xpath[normalize-space() = "//android.widget.Toast"]")
    [POST] http://127.0.0.1:4723/wd/hub/session/98ba717f-e28f-4497-a280-74c55aa57c43/element
    DATA { using: 'xpath', value: './/xpath[normalize-space() = "//android.widget.Toast"]' }
    

  •  类似资料:
    • 问题内容: 我有两个表: 我想从表1中选择所有具有值A和B的表2行的行。这将是行1和3(不是2行,因为它只有A,没有4行是因为只有B)。我可以在没有子查询的情况下执行此操作吗? (注意:我还需要查询表1中的值,因此我不能只查询表2。) 问题答案: 塔达阿!没有子查询。

    • 我正在开发一个数独小程序,我想制作它的单元格(扩展JTextField),以便它只接受0-9和长度为1之间的整数。稍后我会对它进行更多限制(以便它符合游戏规则)。我从: 在这里,我试图过滤输入,对于开始,我只是试图将其限制为整数和一个数字,但似乎我可以输入任意多的数字,而最后一行不会被触发。 想在这里得到一些帮助,谢谢:

    • 假设我有一个spark数据帧,有几列(其中列)和数据帧,有两列:和。 是否有复制以下命令的方法

    • 我有一个RecycerView,其中每个项目都有3个radiobuttons分组在一个RadioGroup中。现在,用户只能在RecycerView中为每个项目选择一个radiobutton。但是我希望用户在整个RecycerView中只选择一个radiobutton。如何做到这一点? 这就是它目前的样子。 我希望在整个回收器视图中只检查1个radiobutton。如果选中了第一项中的第一个单选按

    • 问题内容: 如何在Java中管理两个JRadioButton,以便一次只能选择其中一个?Java中是否有任何方法可以解决此问题,或者您需要构建自己的逻辑? 问题答案: 您必须将它们添加到ButtonGroup中 确保在使用新的构造函数创建按钮后适当添加此代码。

    • 在学习C# winform中,注意到List<T>的集合,只接受一个泛型。 有没有如其他语言那样,可以实现 List<string,bool>这样的集合的。 注意,不是Dictionary<string,bool>,因为键值对中,要求键 为唯一的。 请大佬指导 同上