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: