From a75cb3a0b37513eaac7d6e03ae2e2968457678c2 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 27 Dec 2023 23:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4run=5Fasync=5Fjs()timeout?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_elements/chromium_element.py | 11 ++++------- DrissionPage/_elements/chromium_element.pyi | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 0916987..8eca461 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -364,7 +364,7 @@ class ChromiumElement(DrissionElement): def run_js(self, script, *args, as_expr=False, timeout=None): """对本元素执行javascript代码 - :param script: js文本 + :param script: js文本,文本中用this表示本元素 :param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]... :param as_expr: 是否作为表达式运行,为True时args无效 :param timeout: js超时时间(秒),为None则使用页面timeouts.script设置 @@ -372,17 +372,14 @@ class ChromiumElement(DrissionElement): """ return run_js(self, script, as_expr, self.page.timeouts.script if timeout is None else timeout, args) - def run_async_js(self, script, *args, as_expr=False, timeout=None): + def run_async_js(self, script, *args, as_expr=False): """以异步方式对本元素执行javascript代码 - :param script: js文本 + :param script: js文本,文本中用this表示本元素 :param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]... :param as_expr: 是否作为表达式运行,为True时args无效 - :param timeout: js超时时间(秒),为None则使用页面timeouts.script设置 :return: None """ - from threading import Thread - Thread(target=run_js, args=(self, script, as_expr, self.page.timeouts.script if timeout is None else timeout, - args, True)).start() + run_js(self, script, as_expr, 0, args) def ele(self, loc_or_str, timeout=None): """返回当前元素下级符合条件的第一个元素、属性或节点文本 diff --git a/DrissionPage/_elements/chromium_element.pyi b/DrissionPage/_elements/chromium_element.pyi index 44b6c8d..388a30c 100644 --- a/DrissionPage/_elements/chromium_element.pyi +++ b/DrissionPage/_elements/chromium_element.pyi @@ -167,7 +167,7 @@ class ChromiumElement(DrissionElement): def run_js(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> Any: ... - def run_async_js(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> None: ... + def run_async_js(self, script: str, *args, as_expr: bool = False) -> None: ... def ele(self, loc_or_str: Union[Tuple[str, str], str],