openatx/uiautomator2

lxml.etree._tagValidOrRaise() 提示 Invalid tag name 导致无法获取界面内容

Open

#670 aperta il 8 apr 2021

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Python (1353 fork)batch import
help wanted

Metriche repository

Star
 (5632 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

版本信息

Name: uiautomator2 Version: 2.14.1

问题描述

d.xpath("//*[re:match(@text, '^.*')]").all()提取支付宝首页文本时, 出现异常报错

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-bbe349559290> in <module>
----> 1 d.xpath("//*[re:match(@text, '^.*')]").all()

c:\users\w\anaconda3\lib\site-packages\uiautomator2\xpath.py in all(self, source)
    473 
    474         for node in root.xpath("//node"):
--> 475             node.tag = safe_xmlstr(node.attrib.pop("class", "")) or "node"
    476 
    477         match_sets = []

src/lxml/etree.pyx in lxml.etree._Element.tag.__set__()

src/lxml/apihelpers.pxi in lxml.etree._tagValidOrRaise()

ValueError: Invalid tag name '  '

通过d.dump_hierarchy()获取xml, 发现确实有个class为" "的node项

<node index="0" text="" resource-id="" class="  " package="com.eg.android.AlipayGphone" content-desc="财富生活" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible-to-user="true" bounds="[36,1556][1044,1676]">

用ATX WEditor找到对应项 image

Guida contributor