diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index fff64ab..d9dcaf5 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -828,7 +828,7 @@ class ChromiumBase(BasePage): while self.ready_state not in ('complete', None): sleep(.1) if self._debug or show_errmsg: - print(f'重试 {to_url}') + print(f'重试{t + 1} {to_url}') if err: if show_errmsg: diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index a5f6be1..3be5f88 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -522,15 +522,24 @@ class ChromiumElement(DrissionElement): 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) - def input(self, vals, clear=True): + def input(self, vals, clear=True, by_js=False): """输入文本或组合键,也可用于输入文件路径到input元素(路径间用\n间隔) :param vals: 文本值或按键组合 :param clear: 输入前是否清空文本框 + :param by_js: 是否用js方式输入,不能输入组合键 :return: None """ if self.tag == 'input' and self.attr('type') == 'file': 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'): self.clear(by_js=False) else: diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 1084c65..68b83a5 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -183,7 +183,7 @@ class ChromiumElement(DrissionElement): def get_screenshot(self, path: [str, Path] = None, as_bytes: [bool, str] = None, 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: ...