Calabash iOS: how to get value using query command

烈酒焚心 提交于 2019-12-05 07:22:44

问题


I'm trying to get the value of every class using query command. Below is the sample UI component that I get:

[0] {
          "class" => "UITabBarSwappableImageView",
             "id" => "imageView-34",
           "rect" => {
        "center_x" => 288,
               "y" => 522,
           "width" => 48,
               "x" => 264,
        "center_y" => 538,
          "height" => 32
    },
          "frame" => {
             "y" => 2,
         "width" => 48,
             "x" => 6,
        "height" => 32
    },
          "label" => nil,
    "description" => "<UITabBarSwappableImageVie....>"

On Android, I can just use this to list all the values of class components:

query("*", :class)

However, I can't seem to use the same command on iOS. I get this as the result:

irb(main):135:0> query "*", :class
[
    [ 0] nil,
    [ 1] nil,
    [ 2] nil,
    [ 3] nil
]

I know that with the labels, I can use :accessibilityLabel to do the job, but not when I try to get value from class/id/etc.

Could someone please shed some light?


回答1:


Short answer: 'class' is not a selector on UIView instances

Long answer:

# query( < look for some views >, < selector on the views found > )

# look for buttons marked 'big button' and call 'isSelected' selector on them
query("button marked:'big button'", :isSelected")

# look for labels marked 'title' and call 'text' selector on them
query("label marked:'title'", :text)

# look for all views and call 'class' selector on them
# whoops!  'class' is not a selector on UIView instances
query "*", :class

Taking a step back, I think I know what you are trying to do - get a comprehensive list of views that are visible.

Have a look at https://github.com/jmoody/briar/blob/master/lib/briar/irbrc.rb

Example output is here: https://gist.github.com/jmoody/8031917

Instead of calling 'class' in the query, iterate over the results returned by query and look for the value of the 'class' key.

query('*').map { |result| result['class'] }


来源:https://stackoverflow.com/questions/22214292/calabash-ios-how-to-get-value-using-query-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!