3.2.25元素和动作链增加双击方法;click.at()增加count参数;click.at()改成默认点击中间点

This commit is contained in:
g1879 2023-04-07 00:24:38 +08:00
parent 57b46e7b26
commit 9e509ec256
6 changed files with 37 additions and 14 deletions

View File

@ -99,6 +99,14 @@ class ActionChains:
self._hold(on_ele, 'middle').wait(.05)._release('middle')
return self
def db_click(self, on_ele=None):
"""双击鼠标左键,可先移动到元素上
:param on_ele: ChromiumElement元素或文本定位符
:return: self
"""
self._hold(on_ele, 'left', 2).wait(.05)._release('left')
return self
def hold(self, on_ele=None):
"""按住鼠标左键,可先移动到元素上
:param on_ele: ChromiumElement元素或文本定位符
@ -153,15 +161,16 @@ class ActionChains:
self._release('middle')
return self
def _hold(self, on_ele=None, button='left'):
def _hold(self, on_ele=None, button='left', count=1):
"""按下鼠标按键
:param on_ele: ChromiumElement元素或文本定位符
:param button: 要按下的按键
:param count: 点击次数
:return: self
"""
if on_ele:
self.move_to(on_ele)
self._dr.Input.dispatchMouseEvent(type='mousePressed', button=button, clickCount=1,
self._dr.Input.dispatchMouseEvent(type='mousePressed', button=button, clickCount=count,
x=self.curr_x, y=self.curr_y, modifiers=self.modifier)
return self

View File

@ -31,6 +31,8 @@ class ActionChains:
def m_click(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
def db_click(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
def hold(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
def release(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
@ -43,7 +45,8 @@ class ActionChains:
def m_release(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
def _hold(self, on_ele: Union[ChromiumElement, str] = None, button: str = 'left') -> ActionChains: ...
def _hold(self, on_ele: Union[ChromiumElement, str] = None, button: str = 'left',
count: int = 1) -> ActionChains: ...
def _release(self, button: str) -> ActionChains: ...

View File

@ -1213,8 +1213,7 @@ class NetworkListener(object):
request = self._requests[request_id]
target = request['target']
rd = ResponseData(request_id, request['response'],
body, self._page.tab_id, target)
rd = ResponseData(request_id, request['response'], body, self._page.tab_id, target)
rd.postData = request['post_data']
rd._base64_body = is_base64
rd.requestHeaders = request['request_headers']

View File

@ -1792,26 +1792,36 @@ class Click(object):
x, y = self._ele.locations.viewport_click_point
self._click(x, y, 'middle')
def at(self, offset_x=None, offset_y=None, button='left'):
"""带偏移量点击本元素相对于左上角坐标。不传入x或y值时点击元素click_point
def at(self, offset_x=None, offset_y=None, button='left', count=1):
"""带偏移量点击本元素相对于左上角坐标。不传入x或y值时点击元素中间点
:param offset_x: 相对元素左上角坐标的x轴偏移量
:param offset_y: 相对元素左上角坐标的y轴偏移量
:param button: 点击哪个键可选 left, middle, right, back, forward
:param count: 点击次数
:return: None
"""
self._ele.page.scroll.to_see(self._ele)
if offset_x is None and offset_y is None:
w, h = self._ele.size
offset_x = w // 2
offset_y = h // 2
x, y = offset_scroll(self._ele, offset_x, offset_y)
self._click(x, y, button)
self._click(x, y, button, count)
def _click(self, client_x, client_y, button='left'):
def twice(self):
"""双击元素"""
self.at(count=2)
def _click(self, client_x, client_y, button='left', count=1):
"""实施点击
:param client_x: 视口中的x坐标
:param client_y: 视口中的y坐标
:param button: 'left' 'right'
:param button: 'left' 'right' 'middle' 'back' 'forward'
:param count: 点击次数
:return: None
"""
self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mousePressed',
x=client_x, y=client_y, button=button, clickCount=1)
x=client_x, y=client_y, button=button, clickCount=count)
sleep(.05)
self._ele.page.run_cdp('Input.dispatchMouseEvent', type='mouseReleased',
x=client_x, y=client_y, button=button)

View File

@ -455,9 +455,11 @@ class Click(object):
def middle(self) -> None: ...
def at(self, offset_x: int = None, offset_y: int = None, button='left') -> None: ...
def at(self, offset_x: int = None, offset_y: int = None, button: str = 'left', count: int = 1) -> None: ...
def _click(self, client_x: int, client_y: int, button: str = 'left') -> None: ...
def twice(self, by_js: bool = False) -> None: ...
def _click(self, client_x: int, client_y: int, button: str = 'left', count: int = 1) -> None: ...
class ChromiumScroll(object):

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="3.2.24",
version="3.2.25",
author="g1879",
author_email="g1879@qq.com",
description="Python based web automation tool. It can control the browser and send and receive data packets.",