元素对象间可用==判断是否指向同一个元素;Page的save()默认返回文本,不保存

This commit is contained in:
g1879 2023-12-30 20:51:06 +08:00
parent 34c5ad818b
commit 54d2e3b9de
6 changed files with 19 additions and 19 deletions

View File

@ -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'),

View File

@ -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('页面已被刷新,请尝试等待页面加载完成再执行操作。')

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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