首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Calabash iOS:查询未列出禁用按钮

Calabash iOS:查询未列出禁用按钮
EN

Stack Overflow用户
提问于 2017-01-26 22:20:46
回答 2查看 268关注 0票数 1

我试图验证最初禁用UIButton的continueButton.isEnabled = false是否存在。

当我在calabash-ios console中检查树时,我得到以下结果

代码语言:javascript
复制
[UIWindow] 
  [UIView]   
    [UIView]     
      [MyProject.GradientView]       
      [UIImageView] [id:logo-1] [label:Logo 1]       
      [UIImageView] [id:logo-2] [label:Logo 2]       
      [MyProject.UnderlinedTextField] [label:Email] [text:]       
        [UITextFieldLabel] [label:EMAIL] [text:EMAIL]         
        [UIAccessibilityTextFieldElement] [label:Email] [text:EMAIL]         
      [UIButton] [label:Let's go]       
        [UIButtonLabel] [label:LET'S GO] [text:LET'S GO]         
true

但是,当我尝试使用query("button")时,我会得到一个空数组。如果启用按钮并再次使用查询,则结果是:

代码语言:javascript
复制
[
    [0] {
                          "id" => nil,
                 "description" => "<UIButton: 0x7fcdc8f1b6b0; frame = (23 571; 329 63); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x608000228b20>>",
                       "label" => "Let's go",
                       "frame" => {
                 "y" => 571,
                 "x" => 23,
             "width" => 329,
            "height" => 63
        },
        "accessibilityElement" => true,
                       "value" => nil,
                       "alpha" => 1,
                     "enabled" => true,
                     "visible" => 1,
                    "selected" => false,
                       "class" => "UIButton",
                        "rect" => {
                   "y" => 571,
            "center_x" => 187.5,
            "center_y" => 602.5,
                   "x" => 23,
               "width" => 329,
              "height" => 63
        }
    }
]

为什么在使用查询时没有列出禁用按钮?是否有任何方法验证按钮是否存在,而不管其启用状态如何?

更新

当按照jmoody的建议使用query ("all button")时,我能够得到列出的按钮。

代码语言:javascript
复制
[
    [0] {
                          "id" => nil,
                 "description" => "<UIButton: 0x7fe05ad18000; frame = (23 571; 329 63); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x60000022d940>>",
                       "label" => "Lets go",
                       "frame" => {
                 "y" => 571,
                 "x" => 23,
             "width" => 329,
            "height" => 63
        },
        "accessibilityElement" => true,
                       "value" => nil,
                       "alpha" => 1,
                     "enabled" => false,
                     "visible" => 0,
                    "selected" => false,
                       "class" => "UIButton",
                        "rect" => {
                   "y" => 571,
            "center_x" => 187.5,
            "center_y" => 602.5,
                   "x" => 23,
               "width" => 329,
              "height" => 63
        }
    }
]
EN

回答 2

Stack Overflow用户

发布于 2017-01-27 15:49:35

当按钮被禁用时,它是物理可见的吗?

代码语言:javascript
复制
  # All buttons regardless of visibility.
  query("all button")

  # Ask every button if is enabled.
  query("all button", :isEnabled)

  # Filter buttons by disabled
  query("all button isEnabled:0")

为什么在使用查询时没有列出禁用按钮?

Calabash使用可见性启发式方法来确定视图是否可见。

乍一看,卡拉巴斯似乎不询问是否启用或禁用了UIControl来确定视图是否可见。

票数 1
EN

Stack Overflow用户

发布于 2017-04-27 15:01:43

我也有同样的问题,但我可以提出一个解决办法:

  1. 当按钮被隐藏或可见时,为它指定不同的accessibilityIdentifier,类似于my_super_button_hidden,当它被隐藏时,my_super_button_visible否则
  2. 在按钮查询中始终使用all关键字
  3. 通过检查accessibilityIdentifier检查可见性
  4. 像以前一样检查已启用的状态

在ruby2.4.0,run_loop 2.3.1上进行检查

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41884024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档