Appium + wd(nodejs)获取兄弟元素

时间:2017-06-23 08:40:43

标签: android node.js appium

我使用wd:

在nodejs上有一个appium(android blackbox testing)问题

目前我无法获得兄弟元素。 ID不是唯一的,架构总是相同的 - >

ListView
  |
  |
  Frame
  | |
  | |
  | TextView[@text headline0]
  | |
  | | 
  | Button //no text - just an icon
  |
  Frame
  | |
  | |
  | TextView[@text headline1]
  | |
  | | 
  | Button //no text - just an icon
  |
  Frame
  | |
  ...

我的问题是,我想点击例如旁边的按钮。 headline9。我写了一个scrollToElement(title)函数,只要" headline9"是可见的..

但是现在我无法使用像[//Frame[@index="9"]/]这样的xpath,因为似乎索引在当前可见区域中从0开始重新开始......所以@index="9"可能变成{{1}或者有时@index=2 ..

现在我的想法是使用以下内容选择按钮:

@index=1

但似乎它不起作用(找不到元素)

还有其他人有想法吗?

非常感谢!

2 个答案:

答案 0 :(得分:0)

尝试按elementsByXPath()获取所有TextView,然后以相同方式获取所有按钮。如果TextViews Text等于你的“headline9”,则返回Button,否则迭代找到的TextViews。如果在可见区域找不到它,请滚动并再次进行搜索。

new Promise(function (resolve, reject) {
 (function yourfunctionId(id, context){
  elementsByXPath(Frame[@index=id]TextView){
   elementsByXPath(Frame[@index=id]Button){
    if(TextView[0] === 'undefined'){
     //scroll in ListView
     //call your function recursively from begin (id =0)
     yourfunction(0)
    }
    if(TextView[0].getAttribute('name') == 'headline9'){
     return Button[0]
    }
    else{
     //next
     //call your function recursively
     yourfunction(id++)
    }
   }
  }
)}

您可以滚动查看von Frame-Element的大小,或者您可能需要检查第一帧是否部分可见。

答案 1 :(得分:0)

我希望这会有所帮助

        print(auth_user_id)

获取元素列表,然后找到subElement。我使用的是“yiewd”库,因为“wd”的概念是一样的。 谢谢!