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

相关推荐
Jouzzy5 小时前
【iOS安全】iPhone X iOS 16.7.11 (20H360) WinRa1n 越狱教程
安全·ios·iphone
二流小码农18 小时前
鸿蒙开发:实现一个标题栏吸顶
android·ios·harmonyos
season_zhu18 小时前
iOS开发:关于日志框架
ios·架构·swift
Digitally1 天前
如何在电脑上轻松访问 iPhone 文件
ios·电脑·iphone
安和昂1 天前
【iOS】YYModel源码解析
ios
pop_xiaoli1 天前
UI学习—cell的复用和自定义cell
学习·ui·ios
Daniel_Coder1 天前
Xcode 16.4 + iOS 18 系统运行时崩溃:___cxa_current_primary_exception 符号丢失的原因与解决方案
ios·xcode·ios 18·dyld·libc++abi
烈焰晴天1 天前
使用ReactNative加载Svga动画支持三端【Android/IOS/Harmony】
android·react native·ios
sg_knight1 天前
Flutter嵌入式开发实战 ——从树莓派到智能家居控制面板,打造工业级交互终端
android·前端·flutter·ios·智能家居·跨平台
胖虎12 天前
iOS上传应用包错误问题 “Invalid bundle. The “UIInterfaceOrientationPortrait”“
ios·审核·苹果审核·苹果传包