diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 52c41a6..0ab42ba 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -360,30 +360,30 @@ class ChromiumBase(BasePage): self.wait.load_complete() return self.run_cdp(cmd, **cmd_args) - def run_js(self, script, as_expr=False, *args): + def run_js(self, script, *args, as_expr=False): """运行javascript代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: 运行的结果 """ return run_js(self, script, as_expr, self.timeouts.script, args) - def run_js_loaded(self, script, as_expr=False, *args): + def run_js_loaded(self, script, *args, as_expr=False): """运行javascript代码,执行前等待页面加载完毕 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: 运行的结果 """ self.wait.load_complete() return run_js(self, script, as_expr, self.timeouts.script, args) - def run_async_js(self, script, as_expr=False, *args): + def run_async_js(self, script, *args, as_expr=False): """以异步方式执行js代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: None """ from threading import Thread diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/chromium_base.pyi index 4fdb880..2e03423 100644 --- a/DrissionPage/chromium_base.pyi +++ b/DrissionPage/chromium_base.pyi @@ -121,11 +121,11 @@ class ChromiumBase(BasePage): @property def set(self) -> ChromiumBaseSetter: ... - def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ... + def run_js(self, script: str, *args: Any, as_expr: bool = False) -> Any: ... - def run_js_loaded(self, script: str, as_expr: bool = False, *args: Any) -> Any: ... + def run_js_loaded(self, script: str, *args: Any, as_expr: bool = False) -> Any: ... - def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ... + def run_async_js(self, script: str, *args: Any, as_expr: bool = False) -> None: ... def get(self, url: str, diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 2993c34..93ab47f 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -11,7 +11,7 @@ from warnings import warn from .base import DrissionElement, BaseElement from .common.constants import FRAME_ELEMENT, NoneElement -from .common.errors import ContextLossError, ElementLossError, CallMethodError, JavaScriptError +from .common.errors import ContextLossError, ElementLossError, JavaScriptError from .common.locator import get_loc from .common.web import make_absolute_link, get_ele_txt, format_html, is_js_func, location_in_viewport, offset_scroll from .keys import _keys_to_typing, _keyDescriptionForString, _keyDefinitions @@ -325,20 +325,20 @@ class ChromiumElement(DrissionElement): return format_html(i['value']['value']) - def run_js(self, script, as_expr=False, *args): + def run_js(self, script, *args, as_expr=False): """运行javascript代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: 运行的结果 """ return run_js(self, script, as_expr, self.page.timeouts.script, args) - def run_async_js(self, script, as_expr=False, *args): + def run_async_js(self, script, *args, as_expr=False): """以异步方式执行js代码 :param script: js文本 + :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... :param as_expr: 是否作为表达式运行,为True时args无效 - :param args: 参数,按顺序在js文本中对应argument[0]、argument[2]... :return: None """ from threading import Thread @@ -864,20 +864,20 @@ class ChromiumShadowRootElement(BaseElement): self._states = ShadowRootElementStates(self) return self._states - def run_js(self, script, as_expr=False, *args): + def run_js(self, script, *args, as_expr=False): """运行javascript代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: 运行的结果 """ return run_js(self, script, as_expr, self.page.timeouts.script, args) - def run_async_js(self, script, as_expr=False, *args): + def run_async_js(self, script, *args, as_expr=False): """以异步方式执行js代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: None """ from threading import Thread diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 7346521..4e6723a 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -144,9 +144,9 @@ class ChromiumElement(DrissionElement): def prop(self, prop: str) -> Union[str, int, None]: ... - def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ... + def run_js(self, script: str, *args: Any, as_expr: bool = False) -> Any: ... - def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ... + def run_async_js(self, script: str, *args: Any, as_expr: bool = False) -> None: ... def ele(self, loc_or_str: Union[Tuple[str, str], str], @@ -253,9 +253,9 @@ class ChromiumShadowRootElement(BaseElement): @property def inner_html(self) -> str: ... - def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ... + def run_js(self, script: str, *args: Any, as_expr: bool = False) -> Any: ... - def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ... + def run_async_js(self, script: str, *args: Any, as_expr: bool = False) -> None: ... def parent(self, level_or_loc: Union[str, int] = 1) -> ChromiumElement: ... diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index d4ad311..bea28ee 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -283,11 +283,11 @@ class ChromiumFrame(ChromiumBase): self._check_ok() self.frame_ele.remove_attr(attr) - def run_js(self, script, as_expr=False, *args): + def run_js(self, script, *args, as_expr=False): """运行javascript代码 :param script: js文本 - :param as_expr: 是否作为表达式运行,为True时args无效 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... + :param as_expr: 是否作为表达式运行,为True时args无效 :return: 运行的结果 """ self._check_ok() diff --git a/DrissionPage/chromium_frame.pyi b/DrissionPage/chromium_frame.pyi index db449da..a7c17aa 100644 --- a/DrissionPage/chromium_frame.pyi +++ b/DrissionPage/chromium_frame.pyi @@ -107,7 +107,7 @@ class ChromiumFrame(ChromiumBase): def remove_attr(self, attr: str) -> None: ... - def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ... + def run_js(self, script: str, *args: Any, as_expr: bool = False) -> Any: ... def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[ChromiumElement, None]: ...