diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index a8b5513..ce1a394 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -159,7 +159,7 @@ class Clicker(object): tab = self._ele.page._page if new_tab else self._ele.page - self._ele.click(by_js=by_js) + self.left(by_js=by_js) return tab.wait.download_begin() def to_upload(self, file_paths, by_js=False): @@ -169,9 +169,20 @@ class Clicker(object): :return: None """ self._ele.page.set.upload_files(file_paths) - self._ele.click(by_js=by_js) + self.left(by_js=by_js) self._ele.page.wait.upload_paths_inputted() + def for_new_tab(self, by_js=False): + """点击后等待新tab出现并返回其对象 + :param by_js: 是否使用js点击,逻辑与click()一致 + :return: 新标签页对象,如果没有等到新标签页出现则抛出异常 + """ + self.left(by_js=by_js) + tid = self._ele.page._page.wait.new_tab() + if not tid: + raise RuntimeError('没有出现新标签页。') + return self._ele.page._page.get_tab(tid) + def _click(self, client_x, client_y, button='left', count=1): """实施点击 :param client_x: 视口中的x坐标 diff --git a/DrissionPage/_units/clicker.pyi b/DrissionPage/_units/clicker.pyi index 7aa346d..ac80568 100644 --- a/DrissionPage/_units/clicker.pyi +++ b/DrissionPage/_units/clicker.pyi @@ -10,6 +10,7 @@ from typing import Union from .downloader import DownloadMission from .._elements.chromium_element import ChromiumElement +from .._pages.chromium_tab import WebPageTab, ChromiumTab class Clicker(object): @@ -39,6 +40,8 @@ class Clicker(object): new_tab: bool = False, by_js: bool = False) -> DownloadMission: ... - def to_upload(self, file_paths: Union[str, list, tuple], by_js: bool = False) -> None: ... + def to_upload(self, file_paths: Union[str, Path, list, tuple], by_js: bool = False) -> None: ... + + def for_new_tab(self, by_js:bool=False)->Union[ChromiumTab, WebPageTab]:... def _click(self, client_x: float, client_y: float, button: str = 'left', count: int = 1) -> None: ... diff --git a/DrissionPage/_units/setter.py b/DrissionPage/_units/setter.py index dd0780c..22a3423 100644 --- a/DrissionPage/_units/setter.py +++ b/DrissionPage/_units/setter.py @@ -130,6 +130,8 @@ class ChromiumBaseSetter(BasePageSetter): if isinstance(files, str): files = files.split('\n') + elif isinstance(files, Path): + files = (files, ) self._page._upload_list = [str(Path(i).absolute()) for i in files] def headers(self, headers: dict) -> None: diff --git a/DrissionPage/_units/setter.pyi b/DrissionPage/_units/setter.pyi index 542f733..8695d61 100644 --- a/DrissionPage/_units/setter.pyi +++ b/DrissionPage/_units/setter.pyi @@ -62,7 +62,7 @@ class ChromiumBaseSetter(BasePageSetter): def auto_handle_alert(self, on_off: bool = True, accept: bool = True) -> None: ... - def upload_files(self, files: Union[str, list, tuple]) -> None: ... + def upload_files(self, files: Union[str, Path, list, tuple]) -> None: ... def blocked_urls(self, urls: Union[list, tuple, str, None]) -> None: ...