由于多个对象具有相同的id和contentDescription,因此无法选择单个对象

时间:2016-03-16 10:26:52

标签: android calabash calabash-android

我正在运行calabash-android测试,对于我的查询,响应是

{  
  "id"      =>"recyclerview_businesses",
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.support.v7.widget.RecyclerView@41fdf4a0",
  "class"      =>"android.support.v7.widget.RecyclerView",
  "rect"      =>      {  
     "center_y"         =>429,
     "center_x"         =>240,
     "height"         =>120,
     "y"         =>369,
     "width"         =>480,
     "x"         =>0
  }
},
{  
  "id"      =>nil,
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.widget.LinearLayout@41bdd800",
  "class"      =>"android.widget.LinearLayout",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>69,
     "height"         =>114,
     "y"         =>369,
     "width"         =>90,
     "x"         =>24
  }
 },
 {  
  "id"      =>"icon",
  "enabled"      =>true,
  "contentDescription"      =>"Businees",
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"com.makeramen.roundedimageview.RoundedImageView@41bbfd60",
  "class"      =>"com.makeramen.roundedimageview.RoundedImageView",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>69,
     "height"         =>90,
     "y"         =>381,
     "width"         =>90,
     "x"         =>24
  }
 },
 {  
  "id"      =>nil,
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.widget.LinearLayout@41f38968",
  "class"      =>"android.widget.LinearLayout",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>183,
     "height"         =>114,
     "y"         =>369,
     "width"         =>90,
     "x"         =>138
  }
 },
 {  
  "id"      =>"icon",
  "enabled"      =>true,
  "contentDescription"      =>"Businees",
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"com.makeramen.roundedimageview.RoundedImageView@41e08b88",
  "class"      =>"com.makeramen.roundedimageview.RoundedImageView",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>183,
     "height"         =>90,
     "y"         =>381,
     "width"         =>90,
     "x"         =>138
  }
 },
 {  
  "id"      =>nil,
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.widget.LinearLayout@41fe17f8",
  "class"      =>"android.widget.LinearLayout",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>297,
     "height"         =>114,
     "y"         =>369,
     "width"         =>90,
     "x"         =>252
  }
 },
 {  
  "id"      =>"icon",
  "enabled"      =>true,
  "contentDescription"      =>"Businees",
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"com.makeramen.roundedimageview.RoundedImageView@41ee3028",
  "class"      =>"com.makeramen.roundedimageview.RoundedImageView",
  "rect"      =>      {  
     "center_y"         =>426,
     "center_x"         =>297,
     "height"         =>90,
     "y"         =>381,
     "width"         =>90,
     "x"         =>252
  }
 },
 {  
  "id"      =>nil,
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.widget.RelativeLayout@4205b0f8",
  "class"      =>"android.widget.RelativeLayout",
  "rect"      =>      {  
     "center_y"         =>500,
     "center_x"         =>240,
     "height"         =>25,
     "y"         =>488,
     "width"         =>480,
     "x"         =>0
  }
 },
 {  
  "id"      =>nil,
  "enabled"      =>true,
  "contentDescription"      =>nil,
  "visible"      =>true,
  "tag"      =>nil,
  "description"      =>"android.view.View@41f8d3d8",
  "class"      =>"android.view.View",
  "rect"      =>      {  
     "center_y"         =>500,
     "center_x"         =>101,
     "height"         =>1,
     "y"         =>500,
     "width"         =>202,
     "x"         =>0
  }
 },

在这里,我想选择ID 图标和contentDescription 商家最后一个对象。最后一个是一个按钮,指向另一个弹出窗口。这个问题有什么解决方案吗? 任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

wait_for_element_exists("* id:'icon' contentDescription:'Business'")
last_index = query("* id:'icon' contentDescription:'Business'").length-1
touch("* id:'icon' contentDescription:'Business' index:#{last_index}")

注意:明确总是更好。如果您知道将有多少按钮(您最有可能知道的话),请使用特定索引