AirtestProject / Poco

A cross-engine test automation framework based on UI inspection
http://airtest.netease.com/
Apache License 2.0
1.74k stars 315 forks source link

循环点击一个元素,当元素消失时报错TypeError: object of type 'NoneType' has no len() #592

Open songzhenhua opened 1 year ago

songzhenhua commented 1 year ago

:bulb:相关项目: Poco

标题: [BUG提交]循环点击一个元素,当元素消失时报错TypeError: object of type 'NoneType' has no len()

AirtestIDE版本:

报错描述:     poco从1.0.85升到1.0.89,发现个问题,同样的脚本,场景如下: 一个场景有2个按钮,定义好后,点一下A,再点一下B,循环点,比如点3下A就消失了,此时A.wait()会报错

  File "/Users/szh/opt/miniconda3/envs/test/lib/python3.8/site-packages/poco/proxy.py", line 272, in __len__
    return len(nodes)
TypeError: object of type 'NoneType' has no len()

根据报错内容看到272行是return len(nodes),也就是nodes可能是None。进入到nodes的求值方法_do_query(),发现与1.0.85不一样的地方就是多了一行self.invalidate(),怀疑是1.0.87添加refresh()功能引起的。

暂时修改/poco/proxy.py中len()方法,在272行返回前添加非None判断

if nodes is None:
    nodes = []

之后正常

相关截图:

报错Log:

  File "/Users/szh/opt/miniconda3/envs/test/lib/python3.8/site-packages/poco/proxy.py", line 272, in __len__
    return len(nodes)
TypeError: object of type 'NoneType' has no len()
连接设备信息: 设备类型 设备型号 系统版本号 apk名称/下载链接
Android

提供最小可复现此BUG的代码: