From 38086b11af5cef55986814a60152d1abba074e0e Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 23 Feb 2021 09:43:15 +0800 Subject: [PATCH] =?UTF-8?q?click=5Fat()=E5=8F=82=E6=95=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8E=A5=E6=94=B6=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index 84dfab5..a1c54df 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -345,7 +345,7 @@ class DriverElement(DrissionElement): return False - def click_at(self, x: int = None, y: int = None, by_js=False) -> None: + def click_at(self, x: Union[int, str] = None, y: Union[int, str] = None, by_js=False) -> None: """带偏移量点击本元素,相对于左上角坐标。不传入x或y值时点击元素中点 \n :param x: 相对元素左上角坐标的x轴偏移量 :param y: 相对元素左上角坐标的y轴偏移量 @@ -353,8 +353,8 @@ class DriverElement(DrissionElement): :return: None """ if by_js: - x = self.location['x'] + x if x is not None else self.location['x'] + self.size['width'] // 2 - y = self.location['y'] + y if y is not None else self.location['y'] + self.size['height'] // 2 + x = self.location['x'] + int(x) if x is not None else self.location['x'] + self.size['width'] // 2 + y = self.location['y'] + int(y) if y is not None else self.location['y'] + self.size['height'] // 2 js = f""" var ev = document.createEvent('HTMLEvents'); ev.clientX = {x}; @@ -365,8 +365,8 @@ class DriverElement(DrissionElement): self.run_script(js) else: - x = x if x is not None else self.size['width'] // 2 - y = y if y is not None else self.size['height'] // 2 + x = int(x) if x is not None else self.size['width'] // 2 + y = int(y) if y is not None else self.size['height'] // 2 from selenium.webdriver import ActionChains ActionChains(self.page.driver).move_to_element_with_offset(self.inner_ele, x, y).click().perform()