Merge remote-tracking branch 'origin/master'

This commit is contained in:
g1879 2023-06-19 17:56:04 +08:00
commit 41a8c550bb
3 changed files with 12 additions and 3 deletions

View File

@ -828,7 +828,7 @@ class ChromiumBase(BasePage):
while self.ready_state not in ('complete', None): while self.ready_state not in ('complete', None):
sleep(.1) sleep(.1)
if self._debug or show_errmsg: if self._debug or show_errmsg:
print(f'重试 {to_url}') print(f'重试{t + 1} {to_url}')
if err: if err:
if show_errmsg: if show_errmsg:

View File

@ -522,15 +522,24 @@ class ChromiumElement(DrissionElement):
return self.page._get_screenshot(path, as_bytes=as_bytes, as_base64=as_base64, full_page=False, return self.page._get_screenshot(path, as_bytes=as_bytes, as_base64=as_base64, full_page=False,
left_top=left_top, right_bottom=right_bottom, ele=self) left_top=left_top, right_bottom=right_bottom, ele=self)
def input(self, vals, clear=True): def input(self, vals, clear=True, by_js=False):
"""输入文本或组合键也可用于输入文件路径到input元素路径间用\n间隔) """输入文本或组合键也可用于输入文件路径到input元素路径间用\n间隔)
:param vals: 文本值或按键组合 :param vals: 文本值或按键组合
:param clear: 输入前是否清空文本框 :param clear: 输入前是否清空文本框
:param by_js: 是否用js方式输入不能输入组合键
:return: None :return: None
""" """
if self.tag == 'input' and self.attr('type') == 'file': if self.tag == 'input' and self.attr('type') == 'file':
return self._set_file_input(vals) return self._set_file_input(vals)
if by_js:
if clear:
self.clear(True)
if isinstance(vals, (list, tuple)):
vals = ''.join([str(i) for i in vals])
self.set.prop('value', str(vals))
return
if clear and vals not in ('\n', '\ue007'): if clear and vals not in ('\n', '\ue007'):
self.clear(by_js=False) self.clear(by_js=False)
else: else:

View File

@ -183,7 +183,7 @@ class ChromiumElement(DrissionElement):
def get_screenshot(self, path: [str, Path] = None, as_bytes: [bool, str] = None, def get_screenshot(self, path: [str, Path] = None, as_bytes: [bool, str] = None,
as_base64: [bool, str] = None) -> Union[str, bytes]: ... as_base64: [bool, str] = None) -> Union[str, bytes]: ...
def input(self, vals: Any, clear: bool = True) -> None: ... def input(self, vals: Any, clear: bool = True, by_js: bool = False) -> None: ...
def _set_file_input(self, files: Union[str, list, tuple]) -> None: ... def _set_file_input(self, files: Union[str, list, tuple]) -> None: ...