From 953b6ab90909ab59796e54f74287f6ae5af512da Mon Sep 17 00:00:00 2001 From: kinoshitakenta Date: Thu, 12 Jun 2025 16:29:28 +0800 Subject: [PATCH] feat: improves element click handling Adds retry logic to handle `ElementClickInterceptedException`. This change enhances the robustness of element clicking by implementing a retry mechanism with a timeout. It addresses the issue where clicks are sometimes intercepted (such as scrolling up and down on the page), preventing the action from succeeding. --- utils/EIP_action.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/utils/EIP_action.py b/utils/EIP_action.py index 77f321a..b31d502 100644 --- a/utils/EIP_action.py +++ b/utils/EIP_action.py @@ -125,9 +125,17 @@ class Action(): order_title, img, order_status = a_tag if order_status.text != "【已訂購】": - order_title.click() - open_page_num += 1 - time.sleep(0.05) + for attempt in range(5): + try: + order_title.click() + open_page_num += 1 + time.sleep(0.05) + break # 點成功就跳出 retry + except ElementClickInterceptedException: + print("點擊被遮蔽,重試中...") + time.sleep(0.2) # 等一下再重試 + else: + print("點擊失敗:可能被遮蔽或其他原因") if open_page_num > 0: print(f"已開啟 {open_page_num} 個訂購頁面")