Appium 关于使用 Appium 的 wda 测试 IOS 的 XCUI 框架 app 中元素的问题

yee · 2020年12月23日 · 最后由 yee 回复于 2020年12月24日 · 1722 次阅读

我们的 app 开发目前不支持加入 id,xpath 太慢,所以我基本都用 chan 定位,我发现在不同的 ios 系统中(或者不同的屏幕中),元素的位置顺序会不一样的比如如下,这有办法控制嘛?比如打包的时候加上参数,否则定位就不准了,有经验的大佬说说看呗,谢谢~

ip6 中我知道了的元素位置如下

<XCUIElementTypeWindow>
  <XCUIElementTypeOther>
  <XCUIElementTypeOther>
    <XCUIElementTypeStaticText name="">
  <XCUIElementTypeOther>
    <XCUIElementTypeButton name="我知道了1">
    <XCUIElementTypeButton name="我知道了2">

ip6p 中我知道了的元素位置如下,多了 2 层 XCUIElementTypeOther,而且我知道了的顺序也发生了变化

<XCUIElementTypeWindow>
  <XCUIElementTypeOther>
    <XCUIElementTypeOther>
      <XCUIElementTypeOther>
        <XCUIElementTypeOther>
          <XCUIElementTypeStaticText name="">
        <XCUIElementTypeOther>
          <XCUIElementTypeButton name="我知道了2">
          <XCUIElementTypeButton name="我知道了1">
共收到 2 条回复 时间 点赞

一、app 有啥不支持加入 id 的,不就是类似 button.accessbilityId=xxx 这样的代码嘛,也不会影响功能
二、顺序变化不知道开发逻辑导致的,是不是你每次安装都会导致顺序重新生成。要是元素嵌套链的问题的话:other.other.button["我知道了"],和 other.button["我知道了"],都能定位到你的按钮啊。不用每层都写呢

yee #2 · 2020年12月24日 Author
李鹏 回复

关于第一点,加 id 是可以解决这个问题,但是开发就是不加,要让他们加需要领导协调,比较麻烦。
关于第二点,我的目的其实是要获取一个控件的 text,然而在没有 id 或者不使用 xpath 的情况下,用相对的写法,符合 **/other/other/StaticText 可能有 10 几个,要精确定位,就是需要写成 **/XCUIElementTypeWindow/other/other/StaticText,令人郁闷的是,不同手机同一个元素可能是 **/XCUIElementTypeWindow/other/other/other/other/StaticText

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册