当前位置:网站首页>Autojs学习笔记6:text(txt).findOne()切换app时会报错,最后解决实现效果,切换任何app直到脚本找到指定的txt文字的控件进行点击。
Autojs学习笔记6:text(txt).findOne()切换app时会报错,最后解决实现效果,切换任何app直到脚本找到指定的txt文字的控件进行点击。
2022-06-12 09:20:00 【PYB3】
申明本人使用的autojs是4.1.1版本
目录
使用text(txt).findOne()导致报错
workbench.desktop.main.js:71 [Extension Host] 10:18:49.662/E: Wrapped java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.accessibility.AccessibilityNodeInfo.getPackageName()' on a null object reference ([remote]xfj.js#138)Wrapped java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.accessibility.AccessibilityNodeInfo.getPackageName()' on a null object reference at 领取 ([remote]xfj.js:138:0) at [remote]xfj.js:54:0 at file:///android_asset/modules/__bridges__.js:10:0

核心代码
ui.callbackBtn.click(()=>{
领取()
});
function 领取(){
var b = false;
if(点击目标控件和时间("领取",0)){
b = true;
toastLog("成功点击")
}else{
log("未找到点击按钮")
}
return b
}
/**
* @param {控件内容} txt
* @param {时间} kjTime
* @returns true 找到并处理
*/
function 点击目标控件和时间(txt,kjTime){
var srk1;
if(kjTime==0){
srk1 = text(txt).findOne();
}else{
srk1 = text(txt).findOne(kjTime);
}
if(srk1!=null){
srk1 = srk1.bounds();
click(srk1.centerX(), srk1.centerY());
return true;
}else{
return false;
}
}
疑问
正常情况 代码里的这行 srk1 = text(txt).findOne(); 没找到相关描述的控件就一直阻塞,但如果立马切换到其它app就会报错。(切换到系统界面是正常的)。
使用findOnce()函数也是一样的报错。
解决方法及代码
利用try catch思路来解决!
function 领取(){
var b = false;
try{
if(点击目标控件和时间("领取",0)){
b = true;
toastLog("成功点击")
}else{
log("未找到点击按钮")
}
}catch(err){
log("报错了!!!!")
领取();//报错我就重新调用
}
return b
}结论
使用text(txt).findOne()或是text(txt).findOnce() 只要切换app就会立马报错(测试时,我是人为切换app)。
边栏推荐
- Multi table operation instance
- Counting haybales (difference + discretization)
- What are the software testing requirements analysis methods? Let's have a look
- Basic knowledge of Linear Algebra -- concepts and relationships of common matrices
- Consumer configuration related
- Description of string
- Quick sort
- Mycat的使用
- 自动化测试学习路线,快来学吧
- Full arrangement of numbers (digital password dictionary)
猜你喜欢

JVM virtual machine
Selection of interview questions for software testing
软件测试基础知识分享,写点你不知道的
数据库常见面试题都给你准备好了

Principle analysis of mongodb storage engine wiredtiger

MySQL-MVCC

Multi table operation instance

Definition of polar angle and its code implementation

Introduction to applet cloud development -- questionnaire evaluation applet practice (7)
Database common interview questions are ready for you
随机推荐
Description of string
Can you migrate backwards before the first migration in the south- Can you migrate backwards to before the first migration in South?
剑指 Offer II 016. 不含重复字符的最长子字符串-滑动窗口
Jupyter notebook sets the default browser to open with an error syntaxerror: (Unicode error) 'UTF-8' codec can't decode byte 0xd4
软件测试报告中常见的疏漏,给自己提个醒
The onbindviewholder of recyclerview is called twice at the same time
On absolute value function in C language
Hotspot Metaspace
Consumer configuration related
Sword finger offer:[day 9 dynamic planning (medium)] --- > maximum sum of continuous subarrays
【云原生】具体指什么呢---此文和大伙儿分享答案
How to write test cases?
小程序介绍
Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps
Oracle personal replication (I)
Semaphore flow control semaphore
自动化测试学习路线,快来学吧
Selenium interview question sharing
2022 low voltage electrician retraining question bank and online simulation examination
Four steps for sending rockertmq producer messages