From fb495a99becc3c2e127b3a54abb5527be6028532 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sun, 23 Jun 2024 21:55:46 +0800 Subject: [PATCH] =?UTF-8?q?4.0.5.0=E4=BF=AE=E5=A4=8Dstates.is=5Falive?= =?UTF-8?q?=E5=92=8Cwait.deleted()=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/_units/states.py | 12 ++++++------ DrissionPage/_units/waiter.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index e4e3342..a35b899 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.4.25' +__version__ = '4.0.5.0' diff --git a/DrissionPage/_units/states.py b/DrissionPage/_units/states.py index 47c55dc..763e27f 100644 --- a/DrissionPage/_units/states.py +++ b/DrissionPage/_units/states.py @@ -42,9 +42,9 @@ class ElementStates(object): def is_alive(self): """返回元素是否仍在DOM中""" try: - self._ele.attrs - return True - except Exception: + return self._ele.owner.run_cdp('DOM.describeNode', + backendNodeId=self._ele._backend_id)['node']['nodeId'] != 0 + except ElementLostError: return False @property @@ -101,9 +101,9 @@ class ShadowRootStates(object): def is_alive(self): """返回元素是否仍在DOM中""" try: - self._ele.owner.run_cdp('DOM.describeNode', backendNodeId=self._ele._backend_id) - return True - except Exception: + return self._ele.owner.run_cdp('DOM.describeNode', + backendNodeId=self._ele._backend_id)['node']['nodeId'] != 0 + except ElementLostError: return False diff --git a/DrissionPage/_units/waiter.py b/DrissionPage/_units/waiter.py index 87e19ee..35bf3b4 100644 --- a/DrissionPage/_units/waiter.py +++ b/DrissionPage/_units/waiter.py @@ -495,7 +495,7 @@ class ElementWaiter(OriginWaiter): """ a = self._ele.states.__getattribute__(attr) if (a and mode) or (not a and not mode): - return a + return True if isinstance(a, bool) else a if timeout is None: timeout = self._owner.timeout @@ -503,7 +503,7 @@ class ElementWaiter(OriginWaiter): while perf_counter() < end_time: a = self._ele.states.__getattribute__(attr) if (a and mode) or (not a and not mode): - return a + return True if isinstance(a, bool) else a sleep(.05) err_text = err_text or '等待元素状态改变失败(等待{}秒)。'