diff --git a/DrissionPage/_base/driver.py b/DrissionPage/_base/driver.py index 0b63f80..28b8642 100644 --- a/DrissionPage/_base/driver.py +++ b/DrissionPage/_base/driver.py @@ -161,7 +161,7 @@ class Driver(object): if self._stopped.is_set(): 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) if 'result' not in result and 'error' in result: return {'error': result['error']['message'], 'type': result.get('type', 'call_method_error'), diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 48d64e2..790801f 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -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, awaitPromise=True, userGesture=True, _timeout=timeout, _ignore=AlertExistsError) except TimeoutError: - raise TimeoutError(f'执行js超时({timeout}秒)。') + raise TimeoutError(f'执行js超时(等待{timeout}秒)。') except ContextLostError: if is_page: raise ContextLostError('页面已被刷新,请尝试等待页面加载完成再执行操作。') diff --git a/DrissionPage/_functions/tools.py b/DrissionPage/_functions/tools.py index edfc8ec..640d0cf 100644 --- a/DrissionPage/_functions/tools.py +++ b/DrissionPage/_functions/tools.py @@ -219,7 +219,7 @@ def wait_until(page, condition, timeout=10, poll=0.1, raise_err=True): break if raise_err: - raise TimeoutError(f'等待超时({timeout}秒)') + raise TimeoutError(f'等待超时(等待{timeout}秒)。') else: return False @@ -270,8 +270,8 @@ def raise_error(result, ignore=None): elif error in ('connection disconnected', 'No target with given id found'): r = PageDisconnectedError() elif error == 'timeout': - r = TimeoutError(f'超时。\n错误:{result["error"]}\nmethod:{result["method"]}\nargs:{result["args"]}\n' - f'出现这个错误可能意味着程序有bug,请把错误信息和重现方法告知作者,谢谢。\n' + r = TimeoutError(f'超时(等待{result["timeout"]}秒)。\n错误:{result["error"]}\nmethod:{result["method"]}\nargs:' + f'{result["args"]}\n出现这个错误可能意味着程序有bug,请把错误信息和重现方法告知作者,谢谢。\n' '报告网站:https://gitee.com/g1879/DrissionPage/issues') elif error == 'alert exists.': r = AlertExistsError() diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index df4476e..9c99b3b 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -944,7 +944,7 @@ class ChromiumBase(BasePage): if 'errorText' in result: err = ConnectionError(result['errorText']) except TimeoutError: - err = TimeoutError('页面连接超时。') + err = TimeoutError(f'页面连接超时(等待{timeout}秒)。') if err: if t < times: @@ -963,7 +963,7 @@ class ChromiumBase(BasePage): yu = end_time - perf_counter() ok = self._wait_loaded(1 if yu <= 0 else yu) if not ok: - err = TimeoutError('页面连接超时。') + err = TimeoutError(f'页面连接超时(等待{timeout}秒)。') if t < times: sleep(interval) if self._debug or show_errmsg: diff --git a/DrissionPage/_units/listener.py b/DrissionPage/_units/listener.py index d18759f..c8a8ffb 100644 --- a/DrissionPage/_units/listener.py +++ b/DrissionPage/_units/listener.py @@ -118,7 +118,7 @@ class Listener(object): if fail: if fit_count or not self._caught.qsize(): if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待数据包失败。') + raise WaitTimeoutError(f'等待数据包失败(等待{timeout}秒)。') else: return False else: diff --git a/DrissionPage/_units/waiter.py b/DrissionPage/_units/waiter.py index 7a45607..3fed08e 100644 --- a/DrissionPage/_units/waiter.py +++ b/DrissionPage/_units/waiter.py @@ -43,7 +43,7 @@ class BaseWaiter(object): timeout = end_time - perf_counter() if timeout <= 0: if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待元素显示失败。') + raise WaitTimeoutError(f'等待元素显示失败(等待{timeout}秒)。') else: return False return ele.wait.displayed(timeout, raise_err=raise_err) @@ -62,7 +62,7 @@ class BaseWaiter(object): timeout = end_time - perf_counter() if timeout <= 0: if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待元素显示失败。') + raise WaitTimeoutError(f'等待元素显示失败(等待{timeout}秒)。') else: return False return ele.wait.hidden(timeout, raise_err=raise_err) @@ -78,7 +78,7 @@ class BaseWaiter(object): if ele: return ele if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待元素加载失败。') + raise WaitTimeoutError(f'等待元素加载失败(等待{timeout}秒)。') else: return False @@ -173,7 +173,7 @@ class BaseWaiter(object): sleep(.05) if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError(f'等待{arg}改变失败。') + raise WaitTimeoutError(f'等待{arg}改变失败(等待{timeout}秒)。') else: return False @@ -195,7 +195,7 @@ class BaseWaiter(object): sleep(gap) if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待页面加载失败。') + raise WaitTimeoutError(f'等待页面加载失败(等待{timeout}秒)。') else: return False @@ -266,7 +266,7 @@ class PageWaiter(TabWaiter): sleep(.01) if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待新标签页失败。') + raise WaitTimeoutError(f'等待新标签页失败(等待{timeout}秒)。') else: return False @@ -386,7 +386,7 @@ class ElementWaiter(object): sleep(.05) if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待元素隐藏或被删除失败。') + raise WaitTimeoutError(f'等待元素隐藏或被删除失败(等待{timeout}秒)。') else: return False @@ -418,7 +418,7 @@ class ElementWaiter(object): location = self._ele.rect.location if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError('等待元素停止运动失败。') + raise WaitTimeoutError(f'等待元素停止运动失败(等待{timeout}秒)。') else: return False @@ -428,7 +428,7 @@ class ElementWaiter(object): :param raise_err: 等待失败时是否报错,为None时根据Settings设置 :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): """等待元素某个元素状态到达指定状态 @@ -439,7 +439,7 @@ class ElementWaiter(object): :param err_text: 抛出错误时显示的信息 :return: 是否等待成功 """ - err_text = err_text or '等待元素状态改变失败。' + err_text = err_text or '等待元素状态改变失败(等待{}秒)。' if timeout is None: timeout = self._page.timeout end_time = perf_counter() + timeout @@ -449,7 +449,7 @@ class ElementWaiter(object): sleep(.05) if raise_err is True or Settings.raise_when_wait_failed is True: - raise WaitTimeoutError(err_text) + raise WaitTimeoutError(err_text.format(timeout)) else: return False