当前位置:网站首页>Autojs learning notes 6:text (txt) Findone() will report an error when switching apps. Finally, solve the implementation effect and switch any app until the script finds the control with the specified
Autojs learning notes 6:text (txt) Findone() will report an error when switching apps. Finally, solve the implementation effect and switch any app until the script finds the control with the specified
2022-06-12 09:54:00 【PYB3】
Declare that I use autojs yes 4.1.1 edition
Catalog
Use text(txt).findOne() Result in an error
Use text(txt).findOne() Result in an error
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 receive ([remote]xfj.js:138:0) at [remote]xfj.js:54:0 at file:///android_asset/modules/__bridges__.js:10:0

Core code
ui.callbackBtn.click(()=>{
receive ()
});
function receive (){
var b = false;
if( Click on the target control and time (" receive ",0)){
b = true;
toastLog(" Click... Successfully ")
}else{
log(" Click button not found ")
}
return b
}
/**
* @param { Control content } txt
* @param { Time } kjTime
* @returns true Find and process
*/
function Click on the target control and time (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;
}
}
doubt
Normal condition This line in the code srk1 = text(txt).findOne(); Controls that do not find a description are blocked , But if you immediately switch to another app You're going to report a mistake .( Switching to the system interface is normal ).
Use findOnce() The function also reports an error .
Solution and code
utilize try catch Ideas to solve !
function receive (){
var b = false;
try{
if( Click on the target control and time (" receive ",0)){
b = true;
toastLog(" Click... Successfully ")
}else{
log(" Click button not found ")
}
}catch(err){
log(" Wrong report !!!!")
receive ();// If an error is reported, I will call again
}
return b
}Conclusion
Use text(txt).findOne() or text(txt).findOnce() Just switch app Will immediately report an error ( When testing , I switch artificially app).
边栏推荐
- 科创人·神州数码集团CIO沈旸:最佳实践模式正在失灵,开源加速分布式创新
- Theoretical explanation of hash table
- 基于SSM实现水果商城批发平台
- 六月集训(第12天) —— 链表
- 抽象类和接口
- Implementation of hotspot synchronized
- UE4_ Explore the method of creating background scenes with ready-made resources
- The onbindviewholder of recyclerview is called twice at the same time
- Crazy temporary products: super low price, big scuffle and new hope
- Essentials reading notes
猜你喜欢

MySQL优化之慢日志查询

Transport layer protocol -- TCP protocol

《保护我们的数字遗产:DNA数据存储》白皮书发布

Network layer IP protocol ARP & ICMP & IGMP nat

【云原生 | Kubernetes篇】Kubernetes 网络策略(NetworkPolicy)

哈希表的线性探测法代码实现

Theoretical explanation of hash table

2026年中国软件定义存储市场容量将接近45.1亿美元

III Regular expression to finite state automata: NFA to DFA

List、Set、Map的区别
随机推荐
ThreadLocal
QQ,微信能聊天都靠它(socket)?
The white paper "protecting our digital heritage: DNA data storage" was released
Shen Min, CIO of science and technology innovator Digital China Group: the best practice model is failing, and open source accelerates Distributed Innovation
奇葩错误 -- 轮廓检测检测到边框、膨胀腐蚀开闭运算效果颠倒
QQ, wechat chat depends on it (socket)?
MySQL优化之慢日志查询
Li Yang, a scientific and technological innovator and CIO of the world's top 500 group: the success of digital transformation depends on people. Decision makers should always focus on "firewood"
7-5 zhe zhe playing games
How CEPH improves storage performance and storage stability
科创人·世界500强集团CIO李洋:数字化转型成事在人,决策者应时刻聚焦于「柴」
UEFI EDKII 编程学习
MySQL optimized slow log query
More than 90% of the software companies will ask the software test interview questions. Hurry to recite them
III Regular expression to finite state automata: NFA to DFA
001:数据湖是什么?
IV Transforming regular expressions into finite state automata: DFA minimization
What are the functions of resistance? (super full)
7-4 网红点打卡攻略(dfs)
存储研发工程师招聘