[英]How to find UIButton by title label in calabash ios?
Hy! ! I am trying to write predefined steps in calabash ios for finding a button with a certain title.
我正在尝试在calabash ios中编写预定义步骤,以查找具有特定标题的按钮。 My question is how do I find a certain UIButton using its title label in calabash?
我的问题是如何使用葫芦中的标题标签找到某个UIButton? I've tried the following:
我尝试了以下方法:
Then (/^I see button with title "([^\"]*)" disabled$/) do |buttonTitle|
buttons = query("UIButton").compact
buttons.each do |button|
if query(button, :titleLabel, :text) == buttonTitle
fail(msg="Button found")
return
end
end
end
Why not something like 为什么不这样
Then (/^I should not see button with title "([^\"]*)"$/) do |button_title|
button = query("view marked:'#{button_title}'")
unless button.empty?
screenshot_and_raise "Error: #{button_title} is visible."
end
end
irradio's answer is correct, but I want to add some comments to help you understand what you are doing wrong. irradio的答案是正确的,但我想添加一些评论,以帮助您了解您在做什么错。
# Returns an Array of query results for buttons, #compact
# is not necessary because all the values will be non-nil.
buttons = query("UIButton")
# This is incorrect; you should not pass a query result back to query.
buttons.each do |button|
query(button, ...)
end
# If you wanted to extract titles of all the buttons
query("button descendant label", :text)
=> an Array of titles
# [button titleForState:UIControlStateNormal]
query("button", {:titleForState => 0})
=> an Array of titles for UIControlStateNormal
# [[button titleLabel] text]
query("button", :titleLabel, :text)
=> an Array of titles
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.