mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
优化获取元素瞬间元素被刷新处理方法
This commit is contained in:
parent
3c0a4e45cd
commit
cb66d974a3
@ -338,7 +338,8 @@ class ChromiumBase(BasePage):
|
|||||||
error = r[ERROR]
|
error = r[ERROR]
|
||||||
if error == 'Cannot find context with specified id':
|
if error == 'Cannot find context with specified id':
|
||||||
raise ContextLossError
|
raise ContextLossError
|
||||||
elif error.startswith('Could not find ') and error.endswith(' id'):
|
elif error in ('Could not find node with given id', 'Could not find object with given id',
|
||||||
|
'No node with given id found'):
|
||||||
raise ElementLossError
|
raise ElementLossError
|
||||||
elif error == 'tab closed':
|
elif error == 'tab closed':
|
||||||
raise TabClosedError
|
raise TabClosedError
|
||||||
@ -465,11 +466,13 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
ok = False
|
ok = False
|
||||||
nodeIds = None
|
nodeIds = None
|
||||||
search_result = self.run_cdp_loaded('DOM.performSearch', query=loc, includeUserAgentShadowDOM=True)
|
|
||||||
count = search_result['resultCount']
|
|
||||||
|
|
||||||
timeout = timeout if timeout is not None else self.timeout
|
timeout = timeout if timeout is not None else self.timeout
|
||||||
end_time = perf_counter() + timeout
|
end_time = perf_counter() + timeout
|
||||||
|
|
||||||
|
search_result = self.run_cdp_loaded('DOM.performSearch', query=loc, includeUserAgentShadowDOM=True)
|
||||||
|
count = search_result['resultCount']
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if count > 0:
|
if count > 0:
|
||||||
count = 1 if single else count
|
count = 1 if single else count
|
||||||
@ -482,19 +485,21 @@ class ChromiumBase(BasePage):
|
|||||||
except Exception:
|
except Exception:
|
||||||
sleep(.01)
|
sleep(.01)
|
||||||
|
|
||||||
if ok or perf_counter() >= end_time:
|
if ok:
|
||||||
break
|
try:
|
||||||
|
if single:
|
||||||
|
return make_chromium_ele(self, node_id=nodeIds['nodeIds'][0])
|
||||||
|
else:
|
||||||
|
return [make_chromium_ele(self, node_id=i) for i in nodeIds['nodeIds']]
|
||||||
|
|
||||||
|
except ElementLossError:
|
||||||
|
ok = False
|
||||||
|
|
||||||
search_result = self.run_cdp_loaded('DOM.performSearch', query=loc, includeUserAgentShadowDOM=True)
|
search_result = self.run_cdp_loaded('DOM.performSearch', query=loc, includeUserAgentShadowDOM=True)
|
||||||
count = search_result['resultCount']
|
count = search_result['resultCount']
|
||||||
|
|
||||||
if not nodeIds:
|
if perf_counter() >= end_time:
|
||||||
return NoneElement() if single else []
|
return NoneElement() if single else []
|
||||||
|
|
||||||
if single:
|
|
||||||
return make_chromium_ele(self, node_id=nodeIds['nodeIds'][0])
|
|
||||||
else:
|
|
||||||
return [make_chromium_ele(self, node_id=i) for i in nodeIds['nodeIds']]
|
|
||||||
|
|
||||||
def refresh(self, ignore_cache=False):
|
def refresh(self, ignore_cache=False):
|
||||||
"""刷新当前页面
|
"""刷新当前页面
|
||||||
|
Loading…
x
Reference in New Issue
Block a user