按键精灵ios脚本新增元素功能助力辅助工具开发(三)

元素节点功能(iOSElement)​

在按键精灵 iOS 新版 APP v2.2.0 中,新增了元素节点功能 iOSElement,该功能包含共 15 个函数。这一功能的出现,为开发者在处理 iOS 应用界面元素时提供了更为精准和高效的方式。通过这些函数,开发者能够更加便捷地定位、操作应用中的各种元素,从而实现更复杂的自动化任务。例如,在自动化测试场景中,可以利用 iOSElement 函数快速找到特定的按钮、文本框等元素,并模拟用户的点击、输入等操作,大大提高测试效率。

下面介绍下5个函数信息:iOSElement.ScrollToItem、iOSElement.ClickItem、iOSElement.SelectPicker、iOSElement.DatePicker、iOSElement.GetRect

函数名称

iOSElement.ScrollToItem 将可滚动视图元素滚动到指定的索引项

功能

将可滚动视图元素滚动到指定的索引项

语法

result = iOSElement.ScrollToItem(selector,section,row,dir,animated)

代码范例

Dim result, selector

RunApp "com.apple.Preferences"

Delay 1000

selector = {"id": "UITableView"}

result = iOSElement.ScrollToItem(selector, 3, 10)

If result["code"] = 0 Then

TracePrint "滚动成功"

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.ClickItem 点击可滚动视图元素的指定项

功能

点击可滚动视图元素的指定项,支持完整目标元素节点或者元素查找条件,如查找到多个元素则只操作第一个元素

语法

result = iOSElement.ClickItem(selector,section,row)

代码范例

Dim result, selector

selector = {"id": "UITableView"}

result = iOSElement.ClickItem(selector, 3, 10)

If result["code"] = 0 Then

TracePrint "点击成功"

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.SelectPicker 选择选择器元素的指定项

功能

选择选择器元素的指定项,支持完整目标元素节点或者元素查找条件,如查找到多个元素则只操作第一个元素

语法

result = iOSElement.SelectPicker(selector,section,row,animated)

代码范例

Dim result, selector

RunApp "com.apple.mobiletimer"

Delay 1000

selector = {"text":"计时器"}

iOSElement.Click(selector)

Delay 1000

selector = {"id":"UIPickerView"}

// 设置第1列第5个选项为当前选项

result = iOSElement.SelectPicker(selector, 0, 4, true)

If result["code"] = 0 Then

TracePrint "点击成功"

// 设置第3列第6个选项为当前选项

result = iOSElement.SelectPicker(selector, 2, 5)

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.DatePicker 选择日期选择器元素的指定项

功能

选择日期选择器元素的指定项,支持完整目标元素节点或者元素查找条件,如查找到多个元素则只操作第一个元素

语法

result = iOSElement.DatePicker(selector,date,animated)

代码范例

Dim result, selector

RunApp "com.apple.mobiletimer"

Delay 1000

// 切换到闹钟标签

selector = {"text":"闹钟", "type": "UITabBarButtonLabel"}

iOSElement.Click (selector)

Delay 1000

// 点击右上角加号

selector = {"currentImage":"7f9c421b00d7a2c77128d122e5a36e5058fc47e160be80a84fff0fb13d5da97a"}

iOSElement.Click (selector)

Delay 1000

// 设置时间

selector = {"id": "UIDatePicker"}

result = iOSElement.DatePicker(selector, "2025-04-22 03:08:08")

If result["code"] = 0 Then

TracePrint "点击成功"

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.GetRect 获取指定元素的坐标和宽高

功能

获取指定元素的坐标和宽高

语法

result = iOSElement.GetRect(element)

代码范例

Dim result, selector

selector = {"id":"UIDatePicker"}

result = iOSElement.Find(selector)

If result["code"] = 0 Then

result = iOSElement.GetRect(result["data"])

TracePrint Encode.TableToJson(result["data"])

Else

TracePrint result["msg"]

End If

支持版本:按键精灵iOS新版引擎v2.3.0或以上版本

相关推荐
2501_9160088921 小时前
HTTPS 双向认证抓包实战,原理、难点、工具与可操作的排查流程
网络协议·http·ios·小程序·https·uni-app·iphone
2501_9151063221 小时前
HTTPS 能抓包吗?实战答案与逐步可行方案(HTTPS 抓包原理、证书Pinning双向认证应对、工具对比)
网络协议·http·ios·小程序·https·uni-app·iphone
游戏开发爱好者821 小时前
App HTTPS 抓包实战,原理、常见问题与可行工具路线(开发 测试 安全 角度)
网络协议·安全·ios·小程序·https·uni-app·iphone
2501_9151063221 小时前
App HTTPS 抓包实战指南,原理、常见阻碍、逐步排查与工具组合
网络协议·http·ios·小程序·https·uni-app·iphone
CocoaKier1 天前
苹果海外老账号续费,踩了个大坑!
ios·apple
2501_915106321 天前
上架 App 全流程解析,iOS 应用上架步骤、App Store 审核流程、ipa 文件上传与测试分发经验
android·ios·小程序·https·uni-app·iphone·webview
2501_916013742 天前
苹果应用上架全流程指南 iOS 应用发布步骤、App Store 审核流程、ipa 文件上传与 uni-app 打包实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
2501_915921432 天前
HTTPS 映射如何做?(HTTPS 映射配置、SNI 映射、TLS 终止、内网映射与 iOS 真机验证实战)
android·网络协议·ios·小程序·https·uni-app·iphone
xiAo_Ju2 天前
Xcode 26 option分屏设置
ios