gpt4 book ai didi

iOS 自动化 : how to tap button that has no id

转载 作者:行者123 更新时间:2023-12-01 16:59:08 25 4
gpt4 key购买 nike

我在 logElementTree 中有以下项目输出:

UIAButton: rect:{{20, 427}, {41, 41}}

UIAButton: rect:{{140, 427}, {41, 41}}

这些按钮没有标识符,没有名称,也没有在 XIB 中绘制。在我的自动化测试脚本中,我只使用索引(类似于 target.frontMostApp().mainWindow().buttons()[7].tap() )

但是,这条线并不总是有效,因为索引正在改变。我只是想问一下,除了使用索引之外,是否有其他方法可以点击此按钮?请注意按钮没有名称,所以我不能使用 buttons()["name'"].tap()

最佳答案

从技术上讲,这将是做你想做的事情的最佳方式,所以我会把它留给其他看到这个问题的开发人员。在您的情况下,由于您的技术经验有限,我建议您要求您的开发人员为按钮分配 ID 或名称。为按钮和其他 UI 元素提供好的名称意味着视力受损的用户也可以访问您的应用程序,因为旁白会读出您为按钮指定的名称。以下代码块将以编程方式将标签和可访问性提示分配给符合 UIAccessibility 的动态创建的对象。 .

来自 Apple 的文档(在这种情况下,他们是在 View 上执行此操作,但您可以在任何对象上执行此操作,例如按钮):

- (id)init
{
_view = [[[MyCustomView alloc] initWithFrame:CGRectZero] autorelease];
[_view setIsAccessibilityElement:YES];

[_view setAccessibilityTraits:UIAccessibilityTraitButton];
[_view setAccessibilityLabel:NSLocalizedString(@"view.label", nil)];
[_view setAccessibilityHint:NSLocalizedString(@"view.hint", nil)];
}

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iPhoneAccessibility/Making_Application_Accessible/Making_Application_Accessible.html#//apple_ref/doc/uid/TP40008785-CH102-SW5

Javascript“破解” (不是很干净,但它可以工作......):
var window = UIATarget.localTarget(); 
window.tap({x:yourXCoordinateHere , y:yourYCoordinateHere});

关于iOS 自动化 : how to tap button that has no id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8799405/

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