From 10b3b392cfb8f49047e21901dec04b44fa231a3c Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 19 Apr 2023 18:51:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E6=8B=89=E6=A1=86?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=81=94=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_element.py | 20 ++++++++++++++++++-- DrissionPage/chromium_element.pyi | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index d57d504..32e6ef3 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -1581,7 +1581,7 @@ class Click(object): can_click = True else: end_time = perf_counter() + timeout - while perf_counter() < end_time or timeout == 0: + while perf_counter() < end_time: if self._ele.states.is_in_viewport and self._ele.states.is_enabled and self._ele.states.is_displayed: can_click = True break @@ -1648,7 +1648,7 @@ class Click(object): """ self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mousePressed', x=client_x, y=client_y, button=button, clickCount=count) - sleep(.05) + # sleep(.05) self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mouseReleased', x=client_x, y=client_y, button=button) @@ -1815,9 +1815,13 @@ class ChromiumSelect(object): """反选""" if not self.is_multi: raise TypeError("只能对多项选框执行反选。") + change = False for i in self.options: + change = True mode = 'false' if i.states.is_selected else 'true' i.run_js(f'this.selected={mode};') + if change: + self._dispatch_change() def clear(self): """清除所有已选项""" @@ -1904,9 +1908,11 @@ class ChromiumSelect(object): if self.is_multi: for ele in eles: ele.run_js(f'this.selected={mode};') + self._dispatch_change() return True eles[0].run_js(f'this.selected={mode};') + self._dispatch_change() return True def _select(self, condition, para_type='text', cancel=False, timeout=None): @@ -1954,6 +1960,9 @@ class ChromiumSelect(object): for i in eles: i.run_js(f'this.selected={mode};') + self._dispatch_change() + return True + return False def _index(self, condition, mode, timeout): @@ -1977,8 +1986,15 @@ class ChromiumSelect(object): for i in condition: eles[i - 1].run_js(f'this.selected={mode};') + self._dispatch_change() + return True + return False + def _dispatch_change(self): + """触发修改动作""" + self._ele.run_js('this.dispatchEvent(new UIEvent("change"));') + class ChromiumElementWaiter(object): """等待元素在dom中某种状态,如删除、显示、隐藏""" diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 0196d1f..ca3743b 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -551,6 +551,8 @@ class ChromiumSelect(object): def _index(self, condition: set, mode: str, timeout: float) -> bool: ... + def _dispatch_change(self) -> None: ... + class ChromiumElementWaiter(object): def __init__(self,