mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
完善s_ele()和s_ele()参数
This commit is contained in:
parent
fe2ca2d8c3
commit
171ec15ec0
@ -127,14 +127,14 @@ class DriverElement(DrissionElement):
|
||||
"""
|
||||
return self._ele(loc_or_str, timeout=timeout, single=False)
|
||||
|
||||
def s_ele(self, loc_or_ele=None):
|
||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = None):
|
||||
"""查找第一个符合条件的元素以SessionElement形式返回,处理复杂页面时效率很高 \n
|
||||
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:return: SessionElement对象或属性、文本
|
||||
"""
|
||||
return make_session_ele(self, loc_or_ele)
|
||||
return make_session_ele(self, loc_or_str)
|
||||
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = None):
|
||||
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
||||
:param loc_or_str: 定位符
|
||||
:return: SessionElement或属性、文本组成的列表
|
||||
|
@ -112,14 +112,17 @@ class DriverPage(BasePage):
|
||||
"""
|
||||
return self._ele(loc_or_str, timeout, single=False)
|
||||
|
||||
def s_ele(self, loc_or_ele):
|
||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, DriverElement] = None):
|
||||
"""查找第一个符合条件的元素以SessionElement形式返回,处理复杂页面时效率很高 \n
|
||||
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:return: SessionElement对象或属性、文本
|
||||
"""
|
||||
return make_session_ele(self, loc_or_ele)
|
||||
if isinstance(loc_or_ele, DriverElement):
|
||||
return make_session_ele(loc_or_ele)
|
||||
else:
|
||||
return make_session_ele(self, loc_or_ele)
|
||||
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = None):
|
||||
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:return: SessionElement对象组成的列表
|
||||
|
@ -126,7 +126,7 @@ class SessionElement(DrissionElement):
|
||||
"""
|
||||
return self._ele(loc_or_str)
|
||||
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = None):
|
||||
"""返回当前元素下级所有符合条件的子元素、属性或节点文本 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:return: SessionElement对象或属性、文本组成的列表
|
||||
@ -200,9 +200,9 @@ def make_session_ele(html_or_ele: Union[str, BaseElement, BasePage],
|
||||
# ---------------处理定位符---------------
|
||||
if not loc:
|
||||
if isinstance(html_or_ele, SessionElement):
|
||||
return html_or_ele
|
||||
return html_or_ele if single else [html_or_ele]
|
||||
|
||||
loc = ('xpath', '.')
|
||||
single = True
|
||||
|
||||
elif isinstance(loc, (str, tuple)):
|
||||
loc = get_loc(loc)
|
||||
|
@ -97,7 +97,7 @@ class SessionPage(BasePage):
|
||||
|
||||
return self._url_available
|
||||
|
||||
def ele(self, loc_or_ele: Union[Tuple[str, str], str, SessionElement], timeout=None) \
|
||||
def ele(self, loc_or_ele: Union[Tuple[str, str], str, SessionElement], timeout: float = None) \
|
||||
-> Union[SessionElement, List[SessionElement], str, None]:
|
||||
"""返回页面中符合条件的第一个元素、属性或节点文本 \n
|
||||
:param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||
@ -106,7 +106,7 @@ class SessionPage(BasePage):
|
||||
"""
|
||||
return self._ele(loc_or_ele)
|
||||
|
||||
def eles(self, loc_or_str: Union[Tuple[str, str], str], timeout=None) -> List[SessionElement]:
|
||||
def eles(self, loc_or_str: Union[Tuple[str, str], str], timeout: float = None) -> List[SessionElement]:
|
||||
"""返回页面中所有符合条件的元素、属性或节点文本 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 不起实际作用,用于和DriverElement对应,便于无差别调用
|
||||
@ -114,14 +114,14 @@ class SessionPage(BasePage):
|
||||
"""
|
||||
return self._ele(loc_or_str, single=False)
|
||||
|
||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, SessionElement] = None):
|
||||
"""返回页面中符合条件的第一个元素、属性或节点文本 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||
:param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||
:return: SessionElement对象或属性、文本
|
||||
"""
|
||||
return self._ele(loc_or_str)
|
||||
return make_session_ele(self.html) if loc_or_ele is None else self._ele(loc_or_ele)
|
||||
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = None):
|
||||
"""返回页面中符合条件的所有元素、属性或节点文本 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||
:return: SessionElement对象或属性、文本
|
||||
|
Loading…
x
Reference in New Issue
Block a user