按键精灵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_9159214313 小时前
傻瓜式 HTTPS 抓包,简单抓取iOS设备数据
android·网络协议·ios·小程序·https·uni-app·iphone
恋猫de小郭15 小时前
Flutter 在 Android 出现随机字体裁剪?其实是图层合并时的边界计算问题
android·flutter·ios
2501_9159184116 小时前
把 iOS 性能监控融入日常开发与测试流程的做法
android·ios·小程序·https·uni-app·iphone·webview
Digitally18 小时前
如何轻松地将大型音频文件从 iPhone 发送到不同的设备
ios·iphone
catchadmin19 小时前
PHP 现在可以零成本构建原生 iOS 和 Android 应用 NativePHP for Mobile v3 发布
android·ios·php
TheNextByte120 小时前
如何将照片从 iPhone 传输到三星?
ios·iphone
2501_9159214320 小时前
不用 Xcode 上架 iOS,拆分流程多工具协作完成 iOS 应用的发布准备与提交流程
android·macos·ios·小程序·uni-app·iphone·xcode
Ron丶20 小时前
iOS 旧版本 App 下载方法汇总:如何获取历史版本 IPA(2026 仍有效)
windows·经验分享·macos·ios·电脑
晴天无痕21 小时前
ios OC 获取当前控制器
ios
pop_xiaoli2 天前
OC-实现下载单例类
ios·objective-c·cocoa·xcode