调用textMatches方法,默写机型会直接报错|ScriptThread-0|684fae9
b29cc438f9ae3437e.js] (Spawn-6),5]:找不到方法
com.stardust.autojs.core.accessibility.SimpleActio
nAutomator.text/org.mozilla.javascript.Undefined
,org.mozilla.javascript.Undefined). (file:///android
asset/modules/automator.js#9)
找不到方法 com.stardust.autojs.core.accessibility.
SimpleActionAutomator.text/org.mozilla.javascrip
t.Undefined,org.mozilla.javascript.Undefined).
at performAction (file:///android
asset
/modules/.
automator.js:9:0)
回答
这个问题看起来是你在使用textMatches()
方法时遇到了兼容性问题。根据知识库内容,正确的textMatches()
用法有以下几点需要注意:
- 如果你使用字符串形式的正则表达式,需要用双反斜杠表示单个反斜杠(Java正则语法),例如:
textMatches("\\d+") // 匹配多位数字
- 如果使用JavaScript语法正则表达式则不需要,例如:
textMatches(/\d+/)
- 字符串形式的正则表达式不能以"/"开头和结尾,例如
textMatches("/\\d+/")
是错误的写法。
请检查你的代码是否符合这些规则。如果你的代码无误但仍然报错,可能是ROM兼容性问题,建议尝试改用其他定位方式如text()
或desc()
。
示例正确写法:
// 文档地址 https://docs.hamibot.com/
let widget = textMatches(/按钮\d+/).findOne();
hamibot.exit();
ℹ️ 本回答由 AI 生成,内容仅供参考