定位语句中,在tag:模式下查询文本时,用text()和tx()代替text和tx,避免元素中有text或tx属性时无法定位

This commit is contained in:
g1879 2021-01-09 22:07:19 +08:00
parent 2b5a3ca73d
commit cb8a7e5c11

View File

@ -142,7 +142,7 @@ def str_to_loc(loc: str) -> tuple:
r = re_SPLIT(r'([:=])', at_lst[1], maxsplit=1)
if len(r) == 3:
mode = 'exact' if r[1] == '=' else 'fuzzy'
arg_str = 'text()' if r[0] in ('text', 'tx') else f'@{r[0]}'
arg_str = 'text()' if r[0] in ('text()', 'tx()') else f'@{r[0]}'
loc_str = _make_xpath_str(at_lst[0], arg_str, r[2], mode)
else:
loc_str = f'//*[name()="{at_lst[0]}" and @{r[0]}]'