mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
2.5.6 优化提示框处理、拖拽、清除文本框
This commit is contained in:
parent
7e0e35a463
commit
96e5475c06
@ -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)):
|
||||
|
@ -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):
|
||||
|
@ -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 上
|
||||
|
@ -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)
|
||||
|
2
setup.py
2
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.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user