From e9f6322e5e550915c15afd118b014361c6e90105 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 20 Dec 2023 14:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=84=E7=90=86alert?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_base/driver.py | 6 ++---- DrissionPage/_elements/chromium_element.py | 3 +-- DrissionPage/_functions/keys.py | 6 +++--- DrissionPage/_units/actions.py | 10 +++++----- DrissionPage/_units/clicker.py | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/DrissionPage/_base/driver.py b/DrissionPage/_base/driver.py index c9644ea..91a7465 100644 --- a/DrissionPage/_base/driver.py +++ b/DrissionPage/_base/driver.py @@ -83,10 +83,8 @@ class Driver(object): return result except Empty: - # if self.alert_flag: - # self.alert_flag = False - # self.method_results.pop(ws_id, None) - # return {'result': {'message': 'alert exists.'}} + if self.alert_flag and message['method'].startswith('Input.'): + return {'result': {'message': 'alert exists.'}} if timeout is not None and perf_counter() > end_time: self.method_results.pop(ws_id, None) diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index db64ee5..bd98944 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -641,8 +641,7 @@ class ChromiumElement(DrissionElement): """ self.page.scroll.to_see(self) x, y = offset_scroll(self, offset_x, offset_y) - self.page.run_cdp('Input.dispatchMouseEvent', type='mouseMoved', x=x, y=y, - _ignore=AlertExistsError, _timeout=1) + self.page.run_cdp('Input.dispatchMouseEvent', type='mouseMoved', x=x, y=y, _ignore=AlertExistsError) def drag(self, offset_x=0, offset_y=0, duration=.5): """拖拽当前元素到相对位置 diff --git a/DrissionPage/_functions/keys.py b/DrissionPage/_functions/keys.py index 9ff2637..7e4a300 100644 --- a/DrissionPage/_functions/keys.py +++ b/DrissionPage/_functions/keys.py @@ -404,7 +404,7 @@ def keyDescriptionForString(_modifiers, keyString): # noqa: C901 def send_key(page, modifier, key): """发送一个字,在键盘中的字符触发按键,其它直接发送文本""" if key not in keyDefinitions: - page.run_cdp('Input.insertText', text=key, _ignore=AlertExistsError, _timeout=1) + page.run_cdp('Input.insertText', text=key, _ignore=AlertExistsError) else: description = keyDescriptionForString(modifier, key) @@ -442,7 +442,7 @@ def input_text_or_keys(page, text_or_keys): return if text_or_keys.endswith(('\n', '\ue007')): - page.run_cdp('Input.insertText', text=text_or_keys[:-1], _ignore=AlertExistsError, _timeout=1) + page.run_cdp('Input.insertText', text=text_or_keys[:-1], _ignore=AlertExistsError) send_key(page, modifier, '\n') else: - page.run_cdp('Input.insertText', text=text_or_keys, _ignore=AlertExistsError, _timeout=1) + page.run_cdp('Input.insertText', text=text_or_keys, _ignore=AlertExistsError) diff --git a/DrissionPage/_units/actions.py b/DrissionPage/_units/actions.py index c6a47ac..4f4b282 100644 --- a/DrissionPage/_units/actions.py +++ b/DrissionPage/_units/actions.py @@ -84,8 +84,8 @@ class Actions: t = perf_counter() self.curr_x = x self.curr_y = y - self._dr.run('Input.dispatchMouseEvent', type='mouseMoved', x=self.curr_x, y=self.curr_y, - modifiers=self.modifier, _timeout=1) + self._dr.run('Input.dispatchMouseEvent', type='mouseMoved', + x=self.curr_x, y=self.curr_y, modifiers=self.modifier) ss = .02 - perf_counter() + t if ss > 0: sleep(ss) @@ -188,7 +188,7 @@ class Actions: if on_ele: self.move_to(on_ele, duration=0) self._dr.run('Input.dispatchMouseEvent', type='mousePressed', button=button, clickCount=count, - x=self.curr_x, y=self.curr_y, modifiers=self.modifier, _timeout=1) + x=self.curr_x, y=self.curr_y, modifiers=self.modifier) return self def _release(self, button): @@ -197,7 +197,7 @@ class Actions: :return: self """ self._dr.run('Input.dispatchMouseEvent', type='mouseReleased', button=button, clickCount=1, - x=self.curr_x, y=self.curr_y, modifiers=self.modifier, _timeout=1) + x=self.curr_x, y=self.curr_y, modifiers=self.modifier) return self def scroll(self, delta_x=0, delta_y=0, on_ele=None): @@ -210,7 +210,7 @@ class Actions: if on_ele: self.move_to(on_ele, duration=0) self._dr.run('Input.dispatchMouseEvent', type='mouseWheel', x=self.curr_x, y=self.curr_y, - deltaX=delta_x, deltaY=delta_y, modifiers=self.modifier, _timeout=1) + deltaX=delta_x, deltaY=delta_y, modifiers=self.modifier) return self def up(self, pixel): diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index 6d98dd4..9a85215 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -147,10 +147,10 @@ class Clicker(object): :return: None """ self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mousePressed', x=client_x, - y=client_y, button=button, clickCount=count, _ignore=AlertExistsError, _timeout=.5) + y=client_y, button=button, clickCount=count, _ignore=AlertExistsError) # sleep(.05) self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mouseReleased', x=client_x, - y=client_y, button=button, _ignore=AlertExistsError, _timeout=.5) + y=client_y, button=button, _ignore=AlertExistsError) # -------------即将废弃--------------