From 143bd191c1cccaa2e7de3a745b012e1a1ec2963f Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 19 Jun 2024 17:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=B5=8F=E8=A7=88=E5=99=A8el?= =?UTF-8?q?es()=E7=AD=9B=E9=80=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_functions/elements.py | 345 ++++++++++++++++----------- DrissionPage/_functions/elements.pyi | 150 ++++++------ 2 files changed, 282 insertions(+), 213 deletions(-) diff --git a/DrissionPage/_functions/elements.py b/DrissionPage/_functions/elements.py index 356febc..fc77631 100644 --- a/DrissionPage/_functions/elements.py +++ b/DrissionPage/_functions/elements.py @@ -36,10 +36,9 @@ class ElementsList(list): self._getter = Getter(self) return self._getter - def search(self, get_all=False, displayed=None, checked=None, selected=None, enabled=None, clickable=None, + def search(self, displayed=None, checked=None, selected=None, enabled=None, clickable=None, have_rect=None, have_text=None): """或关系筛选元素 - :param get_all: 是否返回所有筛选到的元素 :param displayed: 是否显示,bool,None为忽略该项 :param checked: 是否被选中,bool,None为忽略该项 :param selected: 是否被选择,bool,None为忽略该项 @@ -49,26 +48,37 @@ class ElementsList(list): :param have_text: 是否含有文本,bool,None为忽略该项 :return: 筛选结果 """ - if get_all: - r = ElementsList() - for i in self: - if ((displayed is not None and (displayed is True and i.states.is_displayed) or ( - displayed is False and not i.states.is_displayed)) - or (checked is not None and (checked is True and i.states.is_checked) or ( - checked is False and not i.states.is_checked)) - or (selected is not None and (selected is True and i.states.is_selected) or ( - selected is False and not i.states.is_selected)) - or (enabled is not None and (enabled is True and i.states.is_enabled) or ( - enabled is False and not i.states.is_enabled)) - or (clickable is not None and (clickable is True and i.states.is_clickable) or ( - clickable is False and not i.states.is_clickable)) - or (have_rect is not None and (have_rect is True and i.states.has_rect) or ( - have_rect is False and not i.states.has_rect)) - or (have_text is not None and (have_text is True and i.raw_text) or ( - have_text is False and not i.raw_text))): - r.append(i) - return r + r = ElementsList(self._page) + for i in self: + if ((displayed is not None and (displayed is True and i.states.is_displayed) or ( + displayed is False and not i.states.is_displayed)) + or (checked is not None and (checked is True and i.states.is_checked) or ( + checked is False and not i.states.is_checked)) + or (selected is not None and (selected is True and i.states.is_selected) or ( + selected is False and not i.states.is_selected)) + or (enabled is not None and (enabled is True and i.states.is_enabled) or ( + enabled is False and not i.states.is_enabled)) + or (clickable is not None and (clickable is True and i.states.is_clickable) or ( + clickable is False and not i.states.is_clickable)) + or (have_rect is not None and (have_rect is True and i.states.has_rect) or ( + have_rect is False and not i.states.has_rect)) + or (have_text is not None and (have_text is True and i.raw_text) or ( + have_text is False and not i.raw_text))): + r.append(i) + return Filter(r) + def search_one(self, displayed=None, checked=None, selected=None, enabled=None, clickable=None, + have_rect=None, have_text=None): + """或关系筛选元素 + :param displayed: 是否显示,bool,None为忽略该项 + :param checked: 是否被选中,bool,None为忽略该项 + :param selected: 是否被选择,bool,None为忽略该项 + :param enabled: 是否可用,bool,None为忽略该项 + :param clickable: 是否可点击,bool,None为忽略该项 + :param have_rect: 是否拥有大小和位置,bool,None为忽略该项 + :param have_text: 是否含有文本,bool,None为忽略该项 + :return: 筛选结果 + """ for i in self: if ((displayed is not None and (displayed is True and i.states.is_displayed) or ( displayed is False and not i.states.is_displayed)) @@ -86,7 +96,7 @@ class ElementsList(list): have_text is False and not i.raw_text))): return i - return NoneElement(self._page, method='filter()', args={'get_all': get_all, 'displayed': displayed, + return NoneElement(self._page, method='filter()', args={'displayed': displayed, 'checked': checked, 'selected': selected, 'enabled': enabled, 'clickable': clickable, 'have_rect': have_rect, 'have_text': have_text}) @@ -96,82 +106,79 @@ class BaseFilter(object): def __init__(self, _list): self._list = _list - def displayed(self): - """返回显示的元素""" - return self._any_state('is_displayed') - - def hidden(self): - """返回不显示的元素""" - return self._any_state('is_displayed', True) - - def checked(self): - """返回被选中的元素""" - return self._any_state('is_checked') - - def not_checked(self): - """返回没被选中的元素""" - return self._any_state('is_checked', True) - - def selected(self): - """返回被选中的列表元素""" - return self._any_state('is_selected') - - def not_selected(self): - """返回没被选中的列表元素""" - return self._any_state('is_selected', True) - - def enabled(self): - """返回有效的元素""" - return self._any_state('is_enabled') - - def disabled(self): - """返回无效的元素""" - return self._any_state('is_enabled', True) - - def clickable(self): - """返回可被点击的元素""" - return self._any_state('is_clickable') - - def not_clickable(self): - """返回不可被点击的元素""" - return self._any_state('is_clickable', True) - - def have_rect(self): - """返回有大小和位置的元素""" - return self._any_state('has_rect') - - def no_rect(self): - """返回没有大小和位置的元素""" - return self._any_state('has_rect', True) - - def style(self, name, value): - """返回拥有某个style值的元素 - :param name: 属性名称 - :param value: 属性值 + def displayed(self, equal=True): + """以是否显示为条件筛选元素 + :param equal: 是否匹配显示的元素,False匹配不显示的 :return: 筛选结果 """ - return self._get_attr(name, value, 'style') + return self._any_state('is_displayed', equal=equal) - def property(self, name, value): - """返回拥有某个property值的元素 - :param name: 属性名称 - :param value: 属性值 + def checked(self, equal=True): + """以是否被选中为条件筛选元素 + :param equal: 是否匹配被选中的元素,False匹配不被选中的 :return: 筛选结果 """ - return self._get_attr(name, value, 'property') + return self._any_state('is_checked', equal=equal) - def attr(self, name, value): - """返回拥有某个attribute值的元素 - :param name: 属性名称 - :param value: 属性值 + def selected(self, equal=True): + """以是否被选择为条件筛选元素,用于