4.0.5.0修复states.is_alive和wait.deleted()问题

This commit is contained in:
g1879 2024-06-23 21:55:46 +08:00
parent b8aa656f45
commit fb495a99be
3 changed files with 9 additions and 9 deletions

View File

@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions
from ._configs.session_options import SessionOptions from ._configs.session_options import SessionOptions
__all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__']
__version__ = '4.0.4.25' __version__ = '4.0.5.0'

View File

@ -42,9 +42,9 @@ class ElementStates(object):
def is_alive(self): def is_alive(self):
"""返回元素是否仍在DOM中""" """返回元素是否仍在DOM中"""
try: try:
self._ele.attrs return self._ele.owner.run_cdp('DOM.describeNode',
return True backendNodeId=self._ele._backend_id)['node']['nodeId'] != 0
except Exception: except ElementLostError:
return False return False
@property @property
@ -101,9 +101,9 @@ class ShadowRootStates(object):
def is_alive(self): def is_alive(self):
"""返回元素是否仍在DOM中""" """返回元素是否仍在DOM中"""
try: try:
self._ele.owner.run_cdp('DOM.describeNode', backendNodeId=self._ele._backend_id) return self._ele.owner.run_cdp('DOM.describeNode',
return True backendNodeId=self._ele._backend_id)['node']['nodeId'] != 0
except Exception: except ElementLostError:
return False return False

View File

@ -495,7 +495,7 @@ class ElementWaiter(OriginWaiter):
""" """
a = self._ele.states.__getattribute__(attr) a = self._ele.states.__getattribute__(attr)
if (a and mode) or (not a and not mode): if (a and mode) or (not a and not mode):
return a return True if isinstance(a, bool) else a
if timeout is None: if timeout is None:
timeout = self._owner.timeout timeout = self._owner.timeout
@ -503,7 +503,7 @@ class ElementWaiter(OriginWaiter):
while perf_counter() < end_time: while perf_counter() < end_time:
a = self._ele.states.__getattribute__(attr) a = self._ele.states.__getattribute__(attr)
if (a and mode) or (not a and not mode): if (a and mode) or (not a and not mode):
return a return True if isinstance(a, bool) else a
sleep(.05) sleep(.05)
err_text = err_text or '等待元素状态改变失败(等待{}秒)。' err_text = err_text or '等待元素状态改变失败(等待{}秒)。'