Skip to content

Commit 9543de0

Browse files
author
yupfa
committed
xpath 增加获取info,text等属性方法
1 parent fd0941a commit 9543de0

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

hmdriver2/_xpath.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def __call__(self, xpath: str) -> '_XMLElement':
2929
raw_bounds: str = node.attrib.get("bounds") # [832,1282][1125,1412]
3030
bounds: Bounds = parse_bounds(raw_bounds)
3131
logger.debug(f"{xpath} Bounds: {bounds}")
32-
return _XMLElement(bounds, self._d)
32+
_xe = _XMLElement(bounds, self._d)
33+
setattr(_xe, "attrib_info", node.attrib)
34+
return _xe
3335

3436
return _XMLElement(None, self._d)
3537

@@ -90,4 +92,18 @@ def long_click(self):
9092
@delay
9193
def input_text(self, text):
9294
self.click()
93-
self._d.input_text(text)
95+
self._d.input_text(text)
96+
97+
@property
98+
@delay
99+
def info(self) -> dict:
100+
if hasattr(self, 'attrib_info'):
101+
return getattr(self, 'attrib_info')
102+
else:
103+
logger.warning("the attribute <attrib_info> does not exists!")
104+
return {}
105+
106+
@property
107+
@delay
108+
def text(self) -> str:
109+
return self.info.get("text")

0 commit comments

Comments
 (0)