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

元素节点功能(iOSElement)​

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

下面介绍下5个函数信息:iOSElement.Source、iOSElement.Find、iOSElement.Finds、iOSElement.FindChild、iOSElement.FindChildren

函数名称

iOSElement.Source 获取整个元素节点信息

功能

获取返回包含整个页面元素节点信息的键值表

语法

result = iOSElement.Source()

代码例子:

Dim result

result = iOSElement.Source()

If result["code"] = 0 Then

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

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.Find 查找并返回第一个符合条件的元素

功能

查找并返回第一个符合条件的元素信息的键值表

语法

result = iOSElement.Find(selector, isRegex)

代码范例

Dim result, selector

RunApp "com.apple.Preferences"

Delay 1000

selector = {"text": "通用"}

result = iOSElement.Find(selector)

If result["code"] = 0 Then

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

Else

TracePrint result["msg"]

End If

// 使用正则匹配模糊查找

selector = {"text": "通.+"}

result = iOSElement.Find(selector, true)

If result["code"] = 0 Then

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

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.Finds 查找并返回所有符合条件的元素

功能

查找并返回所有符合条件的元素信息的键值表

语法

result = iOSElement.Finds(selector, isRegex)

代码范例

Dim result, selector

RunApp "com.apple.Preferences"

Delay 1000

selector = {"id": "UITableViewCellContentView"}

result = iOSElement.Finds(selector)

If result["code"] = 0 Then

For i = 1 To Len(result["data"])

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

Next

Else

TracePrint result["msg"]

End If

// 使用正则匹配模糊查找

selector = {"text": "通.+", "id": "UITableViewLabel"}

result = iOSElement.Finds(selector, true)

If result["code"] = 0 Then

For i = 1 To Len(result["data"])

TracePrint result["data"][i]["text"]

Next

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.FindChild 在指定的父元素下查找并返回第一个符合条件的元素

功能

在指定的父元素下查找并返回第一个符合条件的元素信息键值表

语法

result = iOSElement.FindChild(parent, selector, isRegex)

代码范例

Dim result, parent, selector

RunApp "com.apple.Preferences"

Delay 1000

parent = {"id": "UITableViewCellContentView"}

selector = {"id":"UITableViewLabel"}

result = iOSElement.Find(parent)

If result["code"] = 0 Then

result = iOSElement.FindChild(result["data"], selector)

If result["code"] = 0 Then

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

Else

TracePrint result["msg"]

End If

Else

TracePrint result["msg"]

End If

// 使用正则匹配模糊查找

parent = {"index": 55}

selector = {"text":"[\\u4e00-\\u9fa5]"} '匹配中文

result = iOSElement.Find(parent)

If result["code"] = 0 Then

result = iOSElement.FindChild(result["data"], selector, true)

If result["code"] = 0 Then

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

Else

TracePrint result["msg"]

End If

Else

TracePrint result["msg"]

End If

函数名称

iOSElement.FindChildren 在指定的父元素下查找并返回所有符合条件的元素

功能

在指定的父元素下查找并返回所有符合条件的元素信息的键值表

语法

result =iOSElement.FindChildren(parent, selector, isRegex)

代码范例

Dim result, parent, selector

RunApp "com.apple.Preferences"

Delay 1000

parent = {"id": "UITableView"}

selector = {"id": "PSTableCell"}

result = iOSElement.Find(parent)

If result["code"] = 0 Then

result = iOSElement.FindChildren(result["data"], selector)

If result["code"] = 0 Then

For i = 1 To Len(result["data"])

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

Next

Else

TracePrint result["msg"]

End If

Else

TracePrint result["msg"]

End If

// 使用正则匹配模糊查找

parent = {"id": "UITableView"}

selector = {"text":"[\\u4e00-\\u9fa5]", "id": "UITableViewLabel"} '匹配中文

result = iOSElement.Find(parent)

If result["code"] = 0 Then

result = iOSElement.FindChildren(result["data"], selector, true)

If result["code"] = 0 Then

For i = 1 To Len(result["data"])

TracePrint result["data"][i]["text"]

Next

Else

TracePrint result["msg"]

End If

Else

TracePrint result["msg"]

End If

相关推荐
初级代码游戏1 分钟前
iOS开发 SwiftUI 14:ScrollView 滚动视图
ios·swiftui·swift
初级代码游戏2 小时前
iOS开发 SwitftUI 13:提示、弹窗、上下文菜单
ios·swiftui·swift·弹窗·消息框
zhyongrui5 小时前
托盘删除手势与引导体验修复:滚动冲突、画布消失动画、气泡边框
ios·性能优化·swiftui·swift
Boxsc_midnight9 小时前
【openclaw+imessage】【免费无限流量】集成方案,支持iphone手机+macos
ios·智能手机·iphone
感谢地心引力18 小时前
安卓、苹果手机无线投屏到Windows
android·windows·ios·智能手机·安卓·苹果·投屏
2501_915918411 天前
HTTPS 代理失效,启用双向认证(mTLS)的 iOS 应用网络怎么抓包调试
android·网络·ios·小程序·https·uni-app·iphone
Swift社区1 天前
Flutter 路由系统,对比 RN / Web / iOS 有什么本质不同?
前端·flutter·ios
zhyongrui1 天前
SnipTrip 发热优化实战:从 60Hz 到 30Hz 的性能之旅
ios·swiftui·swift
Andy Dennis1 天前
ios开发 xcode配置
ios·cocoa·xcode
JoyCong19981 天前
iOS 27 六大功能前瞻:折叠屏、AI Siri与“雪豹式”流畅体验,搭配ToDesk开启跨设备新协作
人工智能·ios·cocoa