gpt4 book ai didi

ios - 用户界面自动化 : Check if element exists before tapping

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:16 24 4
gpt4 key购买 nike

我们有一个 iPad 应用程序,其中包含一个两栏新闻阅读器。左 View 包含新闻列表,其中一些直接链接到新闻,一些推送另一个 View Controller 和另一个新闻列表。这也会导致 UIButton 被设置为导航栏的 leftBarButtonItem。如果我们在第一层,则无法点击的简单图像将是 leftBarButtonItem

我现在的目标是进行一项测试,以挖掘第一级的所有新闻。如果新闻指向二级列表,它应该点击导航栏中的 UIButton

我如何检查 leftBarButtonItem 是否“可点击”?由于它可以是图像 按钮,如果它是图像,则仅调用 navigationBar().leftButton().tap() 将导致错误。

如果有任何帮助,我也在使用调整库。

最佳答案

几乎可以点击 UIAutomation 中的所有元素。它是图像、 View 还是按钮都没有关系。如果您尝试点击的对象无效,您将收到错误消息。如何检查:

if ( navigationBar().leftButton().checkIsValid() )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}

或者您可以检查您尝试点击的对象是否是一个按钮,例如(不是最好的方法但它有效):

if ( navigationBar().leftButton().toString() == "[object UIAButton]" )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}

checkIsValid() 适用于所有 UI 元素。如果对象存在,它将返回 truetoString() 将返回 [object UIAElementNil] 如果元素无效或将返回 [object UIAButton][object UIAImage].

也尝试使用 Apple 文档: http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAElementClassReference/UIAElement/UIAElement.html

关于ios - 用户界面自动化 : Check if element exists before tapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11384106/

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