按键精灵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或以上版本

相关推荐
胎粉仔15 分钟前
Objective-c 初阶——异常处理(try-catch)
开发语言·ios·objective-c
转转技术团队2 小时前
iOS微距拍照大揭秘:为什么你的App近距离总是拍不清?
ios
2501_916013745 小时前
移动端 WebView 调试实战,多平台行为差异排查与统一调试流程
android·ios·小程序·https·uni-app·iphone·webview
谈吐大方的鹏sir18 小时前
SwiftUI-TextField组件学习
ios
谈吐大方的鹏sir21 小时前
SwiftUI-Button组件学习
ios
谈吐大方的鹏sir1 天前
SwiftUI-Image组件学习
ios
鹏多多.1 天前
flutter-完美解决键盘弹出遮挡输入框的问题
android·flutter·ios·前端框架
杂雾无尘1 天前
SwiftUI 动画新技能,让你的应用「活」起来!
ios·swiftui·swift
林大鹏天地1 天前
iOS18系统 [YYKVStorage _dbClose] 偶现崩溃
ios
林大鹏天地1 天前
使用Xcode16打包后,App在暗夜模式下,iOS18 切换Tabbar的item,会有一根白色线条闪过。
ios