openatx/uiautomator2

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

Open

#670 ouverte le 8 avr. 2021

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)Python (1 353 forks)batch import
help wanted

Métriques du dépôt

Stars
 (5 632 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

版本信息

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

Guide contributeur