Skip to content

Commit 3a7d6c4

Browse files
authored
Merge pull request #30 from upengfei/xpath-dev
xpath 增加获取info,text等属性方法
2 parents 9639e15 + 9543de0 commit 3a7d6c4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

hmdriver2/_xpath.py

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

3537
return _XMLElement(None, self._d)
3638

@@ -102,4 +104,18 @@ def long_click(self):
102104
@delay
103105
def input_text(self, text):
104106
self.click()
105-
self._d.input_text(text)
107+
self._d.input_text(text)
108+
109+
@property
110+
@delay
111+
def info(self) -> dict:
112+
if hasattr(self, 'attrib_info'):
113+
return getattr(self, 'attrib_info')
114+
else:
115+
logger.warning("the attribute <attrib_info> does not exists!")
116+
return {}
117+
118+
@property
119+
@delay
120+
def text(self) -> str:
121+
return self.info.get("text")

0 commit comments

Comments
 (0)