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

相关推荐
吴Wu涛涛涛涛涛Tao1 天前
基于TCA构建Instagram克隆:SwiftUI状态管理的艺术
ios·swiftui
2501_915921432 天前
iOS 应用上架多环境实战,Windows、Linux 与 Mac 的不同路径
android·ios·小程序·https·uni-app·iphone·webview
Cyclic10012 天前
IOS购买订阅通知信息解析说明Java
java·开发语言·ios
00后程序员张2 天前
iOS 应用上架常见问题与解决方案,多工具组合的实战经验
android·ios·小程序·https·uni-app·iphone·webview
2501_916007473 天前
iOS App 上架实战 从内测到应用商店发布的全周期流程解析
android·ios·小程序·https·uni-app·iphone·webview
wjm0410063 天前
ios八股文 -- Objective-c
开发语言·ios·objective-c
麦兜*4 天前
Swift + Xcode 开发环境搭建终极指南
开发语言·ios·swiftui·xcode·swift·苹果vision pro·swift5.6.3
Digitally4 天前
重置iPhone会删除所有内容吗? 详细回答
ios·iphone
普罗米拉稀4 天前
Flutter 复用艺术:Mixin 与 Abstract 的架构哲学与线性化解密
flutter·ios·面试
kymjs张涛4 天前
零一开源|前沿技术周刊 #12
ios·google·github