页面对象增加upload()方法;

配置对象增加clear_arguments()、clear_prefs()、clear_flags()、clear_headers()方法
This commit is contained in:
g1879 2024-01-28 21:33:54 +08:00
parent 014f86db49
commit 1a6418918c
7 changed files with 50 additions and 6 deletions

View File

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

View File

@ -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: 默认超时时间

View File

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

View File

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

View File

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

View File

@ -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: 要获取的项不设置则返回全部

View File

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