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 '等待元素状态改变失败(等待{}秒)。'