From 701b889447e43594f7bfbe65849ac12405414632 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 18 Aug 2020 14:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drun=5Fscript()=E6=BC=8F?= =?UTF-8?q?=E4=BA=86args=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 7 ++++--- DrissionPage/driver_page.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index 6fe7d50..a297ad7 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -290,12 +290,13 @@ class DriverElement(DrissionElement): print(e) return False - def run_script(self, script: str) -> Any: - """执行js \n + def run_script(self, script: str, *args) -> Any: + """执行js代码,传入自己为第一个参数 \n :param script: js文本 + :param args: 传入的参数 :return: js执行结果 """ - return self.inner_ele.parent.execute_script(script, self.inner_ele) + return self.inner_ele.parent.execute_script(script, self.inner_ele, *args) def submit(self) -> None: """提交表单""" diff --git a/DrissionPage/driver_page.py b/DrissionPage/driver_page.py index e6993c7..b9d2875 100644 --- a/DrissionPage/driver_page.py +++ b/DrissionPage/driver_page.py @@ -216,12 +216,13 @@ class DriverPage(object): """ return None - def run_script(self, script: str) -> Any: - """执行js \n + def run_script(self, script: str, *args) -> Any: + """执行js代码 \n :param script: js文本 + :param args: 传入的参数 :return: js执行结果 """ - return self.driver.execute_script(script) + return self.driver.execute_script(script, *args) @property def tabs_count(self) -> int: