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.
This commit is contained in:
kinoshitakenta 2025-06-12 16:29:28 +08:00
parent 77054f1d84
commit 953b6ab909
Signed by: kinoshitakenta
GPG Key ID: A811E8CA36EF425E
1 changed files with 11 additions and 3 deletions

View File

@ -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} 個訂購頁面")