mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
增加click.to_upload();取消upload()
This commit is contained in:
parent
001c479e4c
commit
6451eab8a4
@ -747,17 +747,6 @@ class ChromiumBase(BasePage):
|
|||||||
frames = self._ele(locator, timeout=timeout, index=None, raise_err=False)
|
frames = self._ele(locator, timeout=timeout, index=None, raise_err=False)
|
||||||
return [i for i in frames if i._type == 'ChromiumFrame']
|
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):
|
def session_storage(self, item=None):
|
||||||
"""返回sessionStorage信息,不设置item则获取全部
|
"""返回sessionStorage信息,不设置item则获取全部
|
||||||
:param item: 要获取的项,不设置则返回全部
|
:param item: 要获取的项,不设置则返回全部
|
||||||
@ -1147,6 +1136,17 @@ class ChromiumBase(BasePage):
|
|||||||
def get_cookies(self, as_dict=False, all_domains=False, all_info=False):
|
def get_cookies(self, as_dict=False, all_domains=False, all_info=False):
|
||||||
return self.cookies(as_dict=as_dict, all_domains=all_domains, all_info=all_info)
|
return self.cookies(as_dict=as_dict, all_domains=all_domains, all_info=all_info)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
class Timeout(object):
|
class Timeout(object):
|
||||||
"""用于保存d模式timeout信息的类"""
|
"""用于保存d模式timeout信息的类"""
|
||||||
|
@ -223,11 +223,6 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def get_frames(self, locator: Union[str, tuple] = None, timeout: float = None) -> List[ChromiumFrame]: ...
|
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(self, cmd: str, **cmd_args) -> dict: ...
|
||||||
|
|
||||||
def run_cdp_loaded(self, cmd: str, **cmd_args) -> dict: ...
|
def run_cdp_loaded(self, cmd: str, **cmd_args) -> dict: ...
|
||||||
|
@ -140,12 +140,13 @@ class Clicker(object):
|
|||||||
"""
|
"""
|
||||||
self.at(count=times)
|
self.at(count=times)
|
||||||
|
|
||||||
def to_download(self, save_path=None, rename=None, suffix=None, new_tab=False):
|
def to_download(self, save_path=None, rename=None, suffix=None, new_tab=False, by_js=False):
|
||||||
"""点击触发下载
|
"""点击触发下载
|
||||||
:param save_path: 保存路径,为None保存在原来设置的,如未设置保存到当前路径
|
:param save_path: 保存路径,为None保存在原来设置的,如未设置保存到当前路径
|
||||||
:param rename: 重命名文件名
|
:param rename: 重命名文件名
|
||||||
:param suffix: 指定文件后缀
|
:param suffix: 指定文件后缀
|
||||||
:param new_tab: 是否在新tab触发下载
|
:param new_tab: 该下载是否在新tab中触发
|
||||||
|
:param by_js: 是否用js方式点击,逻辑与click()一致
|
||||||
:return: DownloadMission对象
|
:return: DownloadMission对象
|
||||||
"""
|
"""
|
||||||
if save_path:
|
if save_path:
|
||||||
@ -158,9 +159,19 @@ class Clicker(object):
|
|||||||
|
|
||||||
tab = self._ele.page._page if new_tab else self._ele.page
|
tab = self._ele.page._page if new_tab else self._ele.page
|
||||||
|
|
||||||
self._ele.click()
|
self._ele.click(by_js=by_js)
|
||||||
return tab.wait.download_begin()
|
return tab.wait.download_begin()
|
||||||
|
|
||||||
|
def to_upload(self, file_paths, by_js=False):
|
||||||
|
"""触发上传文件选择框并自动填入指定路径
|
||||||
|
:param file_paths: 文件路径,如果上传框支持多文件,可传入列表或字符串,字符串时多个文件用回车分隔
|
||||||
|
:param by_js: 是否用js方式点击,逻辑与click()一致
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._ele.page.set.upload_files(file_paths)
|
||||||
|
self._ele.click(by_js=by_js)
|
||||||
|
self._ele.page.wait.upload_paths_inputted()
|
||||||
|
|
||||||
def _click(self, client_x, client_y, button='left', count=1):
|
def _click(self, client_x, client_y, button='left', count=1):
|
||||||
"""实施点击
|
"""实施点击
|
||||||
:param client_x: 视口中的x坐标
|
:param client_x: 视口中的x坐标
|
||||||
|
@ -36,6 +36,9 @@ class Clicker(object):
|
|||||||
save_path: Union[str, Path] = None,
|
save_path: Union[str, Path] = None,
|
||||||
rename: str = None,
|
rename: str = None,
|
||||||
suffix: str = None,
|
suffix: str = None,
|
||||||
new_tab: bool = False) -> DownloadMission: ...
|
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 _click(self, client_x: float, client_y: float, button: str = 'left', count: int = 1) -> None: ...
|
def _click(self, client_x: float, client_y: float, button: str = 'left', count: int = 1) -> None: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user