mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
元素对象间可用==判断是否指向同一个元素;Page的save()默认返回文本,不保存
This commit is contained in:
parent
34c5ad818b
commit
54d2e3b9de
@ -161,7 +161,7 @@ class Driver(object):
|
|||||||
if self._stopped.is_set():
|
if self._stopped.is_set():
|
||||||
return {'error': 'connection disconnected', 'type': 'connection_error'}
|
return {'error': 'connection disconnected', 'type': 'connection_error'}
|
||||||
|
|
||||||
timeout = kwargs.pop('_timeout', 15)
|
timeout = kwargs.pop('_timeout', 30)
|
||||||
result = self._send({'method': _method, 'params': kwargs}, timeout=timeout)
|
result = self._send({'method': _method, 'params': kwargs}, timeout=timeout)
|
||||||
if 'result' not in result and 'error' in result:
|
if 'result' not in result and 'error' in result:
|
||||||
return {'error': result['error']['message'], 'type': result.get('type', 'call_method_error'),
|
return {'error': result['error']['message'], 'type': result.get('type', 'call_method_error'),
|
||||||
|
@ -1413,7 +1413,7 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
arguments=[convert_argument(arg) for arg in args], returnByValue=False,
|
arguments=[convert_argument(arg) for arg in args], returnByValue=False,
|
||||||
awaitPromise=True, userGesture=True, _timeout=timeout, _ignore=AlertExistsError)
|
awaitPromise=True, userGesture=True, _timeout=timeout, _ignore=AlertExistsError)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
raise TimeoutError(f'执行js超时({timeout}秒)。')
|
raise TimeoutError(f'执行js超时(等待{timeout}秒)。')
|
||||||
except ContextLostError:
|
except ContextLostError:
|
||||||
if is_page:
|
if is_page:
|
||||||
raise ContextLostError('页面已被刷新,请尝试等待页面加载完成再执行操作。')
|
raise ContextLostError('页面已被刷新,请尝试等待页面加载完成再执行操作。')
|
||||||
|
@ -219,7 +219,7 @@ def wait_until(page, condition, timeout=10, poll=0.1, raise_err=True):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if raise_err:
|
if raise_err:
|
||||||
raise TimeoutError(f'等待超时({timeout}秒)')
|
raise TimeoutError(f'等待超时(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -270,8 +270,8 @@ def raise_error(result, ignore=None):
|
|||||||
elif error in ('connection disconnected', 'No target with given id found'):
|
elif error in ('connection disconnected', 'No target with given id found'):
|
||||||
r = PageDisconnectedError()
|
r = PageDisconnectedError()
|
||||||
elif error == 'timeout':
|
elif error == 'timeout':
|
||||||
r = TimeoutError(f'超时。\n错误:{result["error"]}\nmethod:{result["method"]}\nargs:{result["args"]}\n'
|
r = TimeoutError(f'超时(等待{result["timeout"]}秒)。\n错误:{result["error"]}\nmethod:{result["method"]}\nargs:'
|
||||||
f'出现这个错误可能意味着程序有bug,请把错误信息和重现方法告知作者,谢谢。\n'
|
f'{result["args"]}\n出现这个错误可能意味着程序有bug,请把错误信息和重现方法告知作者,谢谢。\n'
|
||||||
'报告网站:https://gitee.com/g1879/DrissionPage/issues')
|
'报告网站:https://gitee.com/g1879/DrissionPage/issues')
|
||||||
elif error == 'alert exists.':
|
elif error == 'alert exists.':
|
||||||
r = AlertExistsError()
|
r = AlertExistsError()
|
||||||
|
@ -944,7 +944,7 @@ class ChromiumBase(BasePage):
|
|||||||
if 'errorText' in result:
|
if 'errorText' in result:
|
||||||
err = ConnectionError(result['errorText'])
|
err = ConnectionError(result['errorText'])
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
err = TimeoutError('页面连接超时。')
|
err = TimeoutError(f'页面连接超时(等待{timeout}秒)。')
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
if t < times:
|
if t < times:
|
||||||
@ -963,7 +963,7 @@ class ChromiumBase(BasePage):
|
|||||||
yu = end_time - perf_counter()
|
yu = end_time - perf_counter()
|
||||||
ok = self._wait_loaded(1 if yu <= 0 else yu)
|
ok = self._wait_loaded(1 if yu <= 0 else yu)
|
||||||
if not ok:
|
if not ok:
|
||||||
err = TimeoutError('页面连接超时。')
|
err = TimeoutError(f'页面连接超时(等待{timeout}秒)。')
|
||||||
if t < times:
|
if t < times:
|
||||||
sleep(interval)
|
sleep(interval)
|
||||||
if self._debug or show_errmsg:
|
if self._debug or show_errmsg:
|
||||||
|
@ -118,7 +118,7 @@ class Listener(object):
|
|||||||
if fail:
|
if fail:
|
||||||
if fit_count or not self._caught.qsize():
|
if fit_count or not self._caught.qsize():
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待数据包失败。')
|
raise WaitTimeoutError(f'等待数据包失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -43,7 +43,7 @@ class BaseWaiter(object):
|
|||||||
timeout = end_time - perf_counter()
|
timeout = end_time - perf_counter()
|
||||||
if timeout <= 0:
|
if timeout <= 0:
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待元素显示失败。')
|
raise WaitTimeoutError(f'等待元素显示失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return ele.wait.displayed(timeout, raise_err=raise_err)
|
return ele.wait.displayed(timeout, raise_err=raise_err)
|
||||||
@ -62,7 +62,7 @@ class BaseWaiter(object):
|
|||||||
timeout = end_time - perf_counter()
|
timeout = end_time - perf_counter()
|
||||||
if timeout <= 0:
|
if timeout <= 0:
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待元素显示失败。')
|
raise WaitTimeoutError(f'等待元素显示失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return ele.wait.hidden(timeout, raise_err=raise_err)
|
return ele.wait.hidden(timeout, raise_err=raise_err)
|
||||||
@ -78,7 +78,7 @@ class BaseWaiter(object):
|
|||||||
if ele:
|
if ele:
|
||||||
return ele
|
return ele
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待元素加载失败。')
|
raise WaitTimeoutError(f'等待元素加载失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ class BaseWaiter(object):
|
|||||||
sleep(.05)
|
sleep(.05)
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError(f'等待{arg}改变失败。')
|
raise WaitTimeoutError(f'等待{arg}改变失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ class BaseWaiter(object):
|
|||||||
sleep(gap)
|
sleep(gap)
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待页面加载失败。')
|
raise WaitTimeoutError(f'等待页面加载失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ class PageWaiter(TabWaiter):
|
|||||||
sleep(.01)
|
sleep(.01)
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待新标签页失败。')
|
raise WaitTimeoutError(f'等待新标签页失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ class ElementWaiter(object):
|
|||||||
sleep(.05)
|
sleep(.05)
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待元素隐藏或被删除失败。')
|
raise WaitTimeoutError(f'等待元素隐藏或被删除失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ class ElementWaiter(object):
|
|||||||
location = self._ele.rect.location
|
location = self._ele.rect.location
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError('等待元素停止运动失败。')
|
raise WaitTimeoutError(f'等待元素停止运动失败(等待{timeout}秒)。')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -428,7 +428,7 @@ class ElementWaiter(object):
|
|||||||
:param raise_err: 等待失败时是否报错,为None时根据Settings设置
|
:param raise_err: 等待失败时是否报错,为None时根据Settings设置
|
||||||
:return: 是否等待成功
|
:return: 是否等待成功
|
||||||
"""
|
"""
|
||||||
return self._wait_state('has_rect', True, timeout, raise_err, err_text='等待元素拥有大小及位置属性失败。')
|
return self._wait_state('has_rect', True, timeout, raise_err, err_text='等待元素拥有大小及位置属性失败(等待{}秒)。')
|
||||||
|
|
||||||
def _wait_state(self, attr, mode=False, timeout=None, raise_err=None, err_text=None):
|
def _wait_state(self, attr, mode=False, timeout=None, raise_err=None, err_text=None):
|
||||||
"""等待元素某个元素状态到达指定状态
|
"""等待元素某个元素状态到达指定状态
|
||||||
@ -439,7 +439,7 @@ class ElementWaiter(object):
|
|||||||
:param err_text: 抛出错误时显示的信息
|
:param err_text: 抛出错误时显示的信息
|
||||||
:return: 是否等待成功
|
:return: 是否等待成功
|
||||||
"""
|
"""
|
||||||
err_text = err_text or '等待元素状态改变失败。'
|
err_text = err_text or '等待元素状态改变失败(等待{}秒)。'
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = self._page.timeout
|
timeout = self._page.timeout
|
||||||
end_time = perf_counter() + timeout
|
end_time = perf_counter() + timeout
|
||||||
@ -449,7 +449,7 @@ class ElementWaiter(object):
|
|||||||
sleep(.05)
|
sleep(.05)
|
||||||
|
|
||||||
if raise_err is True or Settings.raise_when_wait_failed is True:
|
if raise_err is True or Settings.raise_when_wait_failed is True:
|
||||||
raise WaitTimeoutError(err_text)
|
raise WaitTimeoutError(err_text.format(timeout))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user