diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 7d17ec5..029e38e 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.4.1' +__version__ = '4.0.4.2' diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index 8dbdf1e..d483967 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -267,6 +267,21 @@ class ChromiumOptions(object): self.clear_file_flags = True return self + def clear_flags(self): + """清空本对象已设置的flag参数""" + self._flags = {} + return self + + def clear_arguments(self): + """清空本对象已设置的argument参数""" + self._arguments = [] + return self + + def clear_prefs(self): + """清空本对象已设置的pref参数""" + self._prefs = {} + return self + def set_timeouts(self, base=None, page_load=None, script=None, implicit=None): """设置超时时间,单位为秒 :param base: 默认超时时间 diff --git a/DrissionPage/_configs/chromium_options.pyi b/DrissionPage/_configs/chromium_options.pyi index 8dd05b2..c682a27 100644 --- a/DrissionPage/_configs/chromium_options.pyi +++ b/DrissionPage/_configs/chromium_options.pyi @@ -109,8 +109,14 @@ class ChromiumOptions(object): def clear_flags_in_file(self) -> ChromiumOptions: ... - def set_timeouts(self, - base: float = None, + def clear_flags(self) -> ChromiumOptions: ... + + def clear_arguments(self) -> ChromiumOptions: ... + + def clear_prefs(self) -> ChromiumOptions: ... + + def set_timeouts(self, + base: float = None, page_load: float = None, script: float = None) -> ChromiumOptions: ... diff --git a/DrissionPage/_configs/session_options.py b/DrissionPage/_configs/session_options.py index 1983801..6373441 100644 --- a/DrissionPage/_configs/session_options.py +++ b/DrissionPage/_configs/session_options.py @@ -198,6 +198,11 @@ class SessionOptions(object): return self + def clear_headers(self): + """清空已设置的header参数""" + self._headers = None + self._del_set.add('headers') + @property def cookies(self): """以list形式返回cookies""" diff --git a/DrissionPage/_configs/session_options.pyi b/DrissionPage/_configs/session_options.pyi index 532dd06..6af3375 100644 --- a/DrissionPage/_configs/session_options.pyi +++ b/DrissionPage/_configs/session_options.pyi @@ -55,6 +55,8 @@ class SessionOptions(object): def remove_a_header(self, name: str) -> SessionOptions: ... + def clear_headers(self) -> SessionOptions: ... + @property def cookies(self) -> list: ... diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index eb0aa96..ebf93f3 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -264,7 +264,6 @@ class ChromiumBase(BasePage): self.stop_loading() # ----------挂件---------- - @property def wait(self): """返回用于等待的对象""" @@ -329,7 +328,7 @@ class ChromiumBase(BasePage): """返回timeouts设置""" return self._timeouts - # ----------挂件---------- + # ----------挂件结束---------- @property def browser(self): @@ -722,6 +721,17 @@ class ChromiumBase(BasePage): frames = self._ele(locator, timeout=timeout, index=None, raise_err=False) return [i for i in frames if i._type == 'ChromiumFrame'] + def upload(self, loc_or_ele, file_paths, by_js=False): + """触发上传文件选择框并自动填入指定路径 + :param loc_or_ele: 被点击后会触发文件选择框的元素或它的定位符 + :param file_paths: 文件路径,如果上传框支持多文件,可传入列表或字符串,字符串时多个文件用回车分隔 + :param by_js: 是否用js方式点击 + :return: None + """ + self.set.upload_files(file_paths) + self.ele(loc_or_ele).click(by_js=by_js) + self.wait.upload_paths_inputted() + def session_storage(self, item=None): """返回sessionStorage信息,不设置item则获取全部 :param item: 要获取的项,不设置则返回全部 diff --git a/DrissionPage/_pages/chromium_base.pyi b/DrissionPage/_pages/chromium_base.pyi index 0b51500..4e09e61 100644 --- a/DrissionPage/_pages/chromium_base.pyi +++ b/DrissionPage/_pages/chromium_base.pyi @@ -176,7 +176,8 @@ class ChromiumBase(BasePage): def get(self, url: str, show_errmsg: bool = False, retry: int = None, interval: float = None, timeout: float = None) -> Union[None, bool]: ... - def cookies(self, as_dict: bool = False, all_domains: bool = False, all_info: bool = False) -> Union[list, dict]: ... + def cookies(self, as_dict: bool = False, all_domains: bool = False, all_info: bool = False) -> Union[ + list, dict]: ... def ele(self, locator: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame], @@ -217,6 +218,11 @@ class ChromiumBase(BasePage): def get_frames(self, locator: Union[str, tuple] = None, timeout: float = None) -> List[ChromiumFrame]: ... + def upload(self, + loc_or_ele: Union[str, Tuple[str, str], ChromiumElement], + file_paths: Union[str, list, tuple], + by_js: bool = False) -> None: ... + def run_cdp(self, cmd: str, **cmd_args) -> dict: ... def run_cdp_loaded(self, cmd: str, **cmd_args) -> dict: ...