gpt4 book ai didi

ios - 如何在 calabash ios 中通过标题标签查找 UIButton?

转载 作者:行者123 更新时间:2023-11-28 21:31:15 26 4
gpt4 key购买 nike

喂!我正在尝试在 calabash ios 中编写预定义步骤以查找具有特定标题的按钮。我的问题是如何在葫芦中使用其标题标签找到某个 UIButton?我尝试了以下方法:

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

最佳答案

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

关于ios - 如何在 calabash ios 中通过标题标签查找 UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35986477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com