From 96e5475c0620466746cfc0dcc187154901158fb5 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 16 Mar 2022 09:54:59 +0800 Subject: [PATCH] =?UTF-8?q?2.5.6=20=E4=BC=98=E5=8C=96=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=A1=86=E5=A4=84=E7=90=86=E3=80=81=E6=8B=96=E6=8B=BD=E3=80=81?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E6=96=87=E6=9C=AC=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 10 +++++----- DrissionPage/driver_page.py | 24 ++++++++++++------------ docs/使用方法/元素操作.md | 6 +++--- docs/使用方法/页面操作.md | 8 ++++---- setup.py | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index eb5b848..8b6be1e 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -586,12 +586,12 @@ class DriverElement(DrissionElement): except Exception: pass - def clear(self, insure_clear: bool = True) -> Union[None, bool]: + def clear(self, insure: bool = True) -> Union[None, bool]: """清空元素文本 \n - :param insure_clear: 是否确保清空 + :param insure: 是否确保清空 :return: 是否清空成功,不能清空的元素返回None """ - if insure_clear: + if insure: return self.input('') else: @@ -694,7 +694,7 @@ class DriverElement(DrissionElement): :param y: y变化值 :param speed: 拖动的速度,传入0即瞬间到达 :param shake: 是否随机抖动 - :return: 是否推拽成功 + :return: None """ x += self.location['x'] + self.size['width'] // 2 y += self.location['y'] + self.size['height'] // 2 @@ -708,7 +708,7 @@ class DriverElement(DrissionElement): :param ele_or_loc: 另一个元素或坐标元组,坐标为元素中点的坐标 :param speed: 拖动的速度,传入0即瞬间到达 :param shake: 是否随机抖动 - :return: 是否拖拽成功 + :return: None """ # x, y:目标点坐标 if isinstance(ele_or_loc, (DriverElement, WebElement)): diff --git a/DrissionPage/driver_page.py b/DrissionPage/driver_page.py index 260f3db..e0d0d2f 100644 --- a/DrissionPage/driver_page.py +++ b/DrissionPage/driver_page.py @@ -462,10 +462,10 @@ class DriverPage(BasePage): """ return glob(f'{download_path}{sep}*.crdownload') - def process_alert(self, mode: str = 'ok', text: str = None, timeout: float = None) -> Union[str, None]: + def process_alert(self, ok: bool = True, send: str = None, timeout: float = None) -> Union[str, None]: """处理提示框 \n - :param mode: 'ok' 或 'cancel',若输入其它值,不会按按钮但依然返回文本值 - :param text: 处理prompt提示框时可输入文本 + :param ok: True表示确认,False表示取消,其它值不会按按钮但依然返回文本值 + :param send: 处理prompt提示框时可输入文本 :param timeout: 等待提示框出现的超时时间 :return: 提示框内容文本,未等到提示框则返回None """ @@ -479,23 +479,23 @@ class DriverPage(BasePage): timeout = timeout if timeout is not None else self.timeout t1 = perf_counter() alert = do_it() - while not alert and perf_counter() - t1 <= timeout: + while alert is False and perf_counter() - t1 <= timeout: alert = do_it() - if not alert: + if alert is False: return None - if text: - alert.send_keys(text) + res_text = alert.text - text = alert.text + if send is not None: + alert.send_keys(send) - if mode == 'cancel': - alert.dismiss() - elif mode == 'ok': + if ok is True: alert.accept() + elif ok is False: + alert.dismiss() - return text + return res_text class ToFrame(object): diff --git a/docs/使用方法/元素操作.md b/docs/使用方法/元素操作.md index 98aa2f4..329a0ad 100644 --- a/docs/使用方法/元素操作.md +++ b/docs/使用方法/元素操作.md @@ -130,7 +130,7 @@ ele.input('D:\\test1.txt\nD:\\test2.txt') 参数: -- insure_clear:是否确保清空。为`True`则用`input()`确保值变成`''`,为`False`则用 selenium 元素`clear()`方法 +- insure:是否确保清空。为`True`则用`input()`确保值变成`''`,为`False`则用 selenium 元素`clear()`方法 返回:`bool`,是否清空成功,不能清空的元素返回`None` @@ -275,7 +275,7 @@ ele.submit() - speed:拖动的速度,传入 0 即瞬间到达 - shake:是否随机抖动 -返回:`bool`,表示是否拖动成功 +返回:None ```python # 拖动当前元素到距离 50*50 的位置,速度为 100,不随机抖动 @@ -292,7 +292,7 @@ ele.drag(50, 50, 100, False) - speed: 拖动的速度,传入 0 即瞬间到达 - shake: 是否随机抖动 -返回:bool,表示是否拖动成功 +返回:None ```python # 把 ele1 拖拽到 ele2 上 diff --git a/docs/使用方法/页面操作.md b/docs/使用方法/页面操作.md index 57aefd5..0e5a3cb 100644 --- a/docs/使用方法/页面操作.md +++ b/docs/使用方法/页面操作.md @@ -503,8 +503,8 @@ page.set_window_size(800, 600) 参数: -- mode:`'ok'`或`'cancel'`,若输入其它值,不会按按钮但依然返回文本值 -- text:处理 prompt 提示框时可输入文本 +- ok:`True`表示确认,`False`表示取消,其它值不会按按钮但依然返回文本值 +- send:处理 prompt 提示框时可输入文本 - timeout:等待提示框出现的超时时间 返回:提示框内容文本,未等到提示框则返回`None` @@ -514,10 +514,10 @@ page.set_window_size(800, 600) txt = page.process_alert() # 点击取消 -page.process_alert('cancel') +page.process_alert(False) # 给 prompt 提示框输入文本并点击确定 -paeg.process_alert('ok', 'some text') +paeg.process_alert(True, 'some text') # 不处理提示框,只获取提示框文本 txt = page.process_alert(None) diff --git a/setup.py b/setup.py index de81411..c92ccd5 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="2.5.5", + version="2.5.6", author="g1879", author_email="g1879@qq.com", description="A module that integrates selenium and requests session, encapsulates common page operations.",