UiAutomator 求 UIAutomator2.0 的 hasObject 方法、findObject 方法随机抛空指针异常的 Bug 解决方案

itisacoolday · 2017年03月15日 · 最后由 文平 回复于 2017年03月28日 · 1780 次阅读

使用的 uiautomator-v18:2.1.2。

正常情况下,调用 hasObject 方法、findObject、wait 方法寻找控件,理应返回找到或没找到、找到的对象或没找到的空对象等,但是却在测试过程中,发现这些函数会随机返回空指针异常的报错。因此重写了 wait 方法,将 hasObject 或 findObject 方法用 try catch 包起来,并放至时间循环中执行一段时间,确保随机出现的一次空指针异常不会影响控件的继续反复查找。代码如下:

protected boolean hasObjectAndWait(BySelector selector,long timeout) throws Exception{
boolean mObjectExist = false;
boolean checkResult = false;
long st,st1,du,et,et1;
st=System.currentTimeMillis();
du=st+timeout;
while(System.currentTimeMillis()<=du){
try {
st1 = System.currentTimeMillis();
mObjectExist = mUIDevice.hasObject(selector);
et1 = System.currentTimeMillis();
logger.log("hasObject "+ selector + " result=" + mObjectExist + "; time=" + String.valueOf(parseMs2M(et1-st1)));
} catch (Exception e) {
logger.log( " ****** invoke hasObject occured exception , e = " + e.toString());
};
if(mObjectExist){
checkResult = true;
break;
}
}
et=System.currentTimeMillis();
logger.log("hasObjectAndWait " + selector +" result=" + checkResult + "; time=" + String.valueOf(parseMs2M(et-st)));
return checkResult;
}

以跳转至首页、查找 “扫一扫” 控件为例,执行的日志片段如下:

2017-03-14 17:07:14.580 DEBUG:将识别目标控件:mShouYe
2017-03-14 17:07:14.595 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.609 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.624 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.638 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.653 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.672 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.686 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.700 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.714 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.732 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.756 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.773 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.792 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.805 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.819 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.832 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.855 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.869 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:14.885 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.902 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.917 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.935 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.952 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.969 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:14.986 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.003 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.025 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.040 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.056 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.075 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.090 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.105 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.120 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.135 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.150 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.168 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.190 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.208 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.224 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.239 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.255 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.271 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.286 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.302 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.316 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.330 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.345 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.360 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.376 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.391 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.406 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.421 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.435 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.453 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.468 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.484 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.499 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.513 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.527 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.548 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.564 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.580 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.594 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.608 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.622 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.635 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.649 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.663 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.676 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.691 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:15.710 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.749 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:15.771 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.814 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:15.845 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:15.880 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:15.907 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:15.925 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.955 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:15.979 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:15.999 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.048 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.05
2017-03-14 17:07:16.091 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:16.111 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.135 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.161 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.177 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.212 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.241 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.256 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:16.281 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.297 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:16.317 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.344 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.361 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.382 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.417 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.433 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.447 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:16.470 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.501 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.516 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.01
2017-03-14 17:07:16.542 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.574 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.605 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.629 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.651 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.708 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.06
2017-03-14 17:07:16.737 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.764 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.788 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.818 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:16.840 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:16.876 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:16.918 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:16.995 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.07
2017-03-14 17:07:17.022 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.048 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.102 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.05
2017-03-14 17:07:17.133 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.193 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.06
2017-03-14 17:07:17.250 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.06
2017-03-14 17:07:17.276 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.309 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.351 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.04
2017-03-14 17:07:17.416 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.06
2017-03-14 17:07:17.540 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.12
2017-03-14 17:07:17.564 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.586 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.611 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.632 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.656 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.677 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.704 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.737 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.758 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.783 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.805 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.835 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.866 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:17.929 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.06
2017-03-14 17:07:17.956 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:17.987 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:18.021 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:18.048 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:18.081 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:18.106 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.127 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.148 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.173 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.196 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.221 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.244 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.269 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.290 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.310 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.331 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.351 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.371 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.391 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.411 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.431 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.463 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.03
2017-03-14 17:07:18.483 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.507 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.532 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.02
2017-03-14 17:07:18.616 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.08
2017-03-14 17:07:18.671 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.05
2017-03-14 17:07:18.769 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.1
2017-03-14 17:07:19.531 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=false; time=0.76
2017-03-14 17:07:20.477 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:20.688 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:20.733 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:20.896 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:21.026 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:22.368 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:22.379 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:22.416 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.319 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.470 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.473 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.476 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.481 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.492 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.494 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.502 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.510 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.513 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.516 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.519 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.527 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.531 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.534 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.536 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.539 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.541 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.544 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.549 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.569 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.571 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.576 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.589 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.591 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.603 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.606 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.613 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.645 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.654 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.666 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.669 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.672 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.676 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.722 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.729 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.753 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.770 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.775 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:23.815 DEBUG: ****** invoke hasObject occured exception , e = java.lang.NullPointerException
2017-03-14 17:07:24.859 DEBUG:hasObject BySelector [TEXT='\Q 扫一扫\E'] result=true; time=1.04
2017-03-14 17:07:24.865 DEBUG:hasObjectAndWait BySelector [TEXT='\Q 扫一扫\E'] result=true; time=10.28

可以看出:在等待某个控件(如 “扫一扫”)出现的过程中,从 2017-03-14 17:07:14.595 至 17:07:19.531 过程中,hasobject 都正常返回没有找到,但是之后,出现一系列抛异常,也就是说,也许在这之后会有某次提前找到控件,但是因为抛异常没能返回正常 true 值,导致继续寻找控件,直至 2017-03-14 17:07:24.859 恢复正常,得到结果 true 值。

这种方式虽然可以最终正常识别到控件,但是对于需要计算查找控件时延的需求来说,会拉长统计时间。

请问各位大神,有何解决方法?

共收到 2 条回复 时间 点赞

把错误堆栈打出来,一级级往下看是哪里出的空指针

遇见了同样的问题,感觉安卓 7 上 UIA2.0 有大坑啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册