From fe2ca2d8c32343d05861f08f1f5bb7e6615457e1 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 27 Dec 2021 22:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=89=E5=BE=85=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 8 ++++++-- DrissionPage/shadow_root_element.py | 9 ++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index c52f9ed..23c1e27 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -362,8 +362,12 @@ class DriverElement(DrissionElement): if not by_js: timeout = timeout if timeout is not None else self.page.timeout t1 = perf_counter() - while not do_it() and perf_counter() - t1 <= timeout: - pass + click = do_it() + while not click and perf_counter() - t1 <= timeout: + click = do_it() + + if click: + return True # 若点击失败,用js方式点击 if by_js is not False: diff --git a/DrissionPage/shadow_root_element.py b/DrissionPage/shadow_root_element.py index 994d6bc..c95f44b 100644 --- a/DrissionPage/shadow_root_element.py +++ b/DrissionPage/shadow_root_element.py @@ -144,15 +144,10 @@ class ShadowRootElement(BaseElement): loc = loc[0], loc[1][5:] timeout = timeout if timeout is not None else self.page.timeout - eles = make_session_ele(self.html).eles(loc) - t1 = perf_counter() + eles = make_session_ele(self.html).eles(loc) while not eles and perf_counter() - t1 <= timeout: - try: - eles = make_session_ele(self.html).eles(loc) - - except Exception: - pass + eles = make_session_ele(self.html).eles(loc) if not eles: return None if single else eles