@@ -69,6 +69,8 @@ class GLOBALS:
6969WD_FETCH_INVITE_CLOUDFLARE_TRIES = 3
7070WD_FETCH_INVITE_CLOUDFLARE_DELAY = 7
7171
72+ WD_CAPTCHA_RETRIES = 3
73+
7274WD_RD_CLICK_UPPER_N = 5
7375WD_RD_CLICK_LOWER_N = 2
7476WD_OUTPUT_PATH = pathlib .Path .home ().joinpath ("daf/daf_web_data" )
@@ -83,6 +85,9 @@ class GLOBALS:
8385TOP_GG_SERVER_JOIN_URL = "https://top.gg/servers/{id}/join"
8486
8587
88+ XPATH_CAPTCHA = "//iframe[contains(@src, 'captcha')]"
89+
90+
8691@doc .doc_category ("Clients" )
8792class SeleniumCLIENT :
8893 """
@@ -448,13 +453,21 @@ async def await_captcha(self):
448453 trace ("Awaiting CAPTCHA" , TraceLEVELS .DEBUG )
449454 await asyncio .sleep (WD_TIMEOUT_SHORT )
450455 try :
456+ driver = self .driver
451457 # CAPTCHA detected, wait until it is solved by the user
452- await self .async_execute (
453- WebDriverWait (self .driver , WD_TIMEOUT_LONG ).until_not ,
454- presence_of_element_located (
455- (By .XPATH , "//iframe[contains(@src, 'captcha')]" )
458+ for _ in range (WD_CAPTCHA_RETRIES ):
459+ await self .async_execute (
460+ WebDriverWait (driver , WD_TIMEOUT_LONG ).until_not ,
461+ presence_of_element_located (
462+ (By .XPATH , XPATH_CAPTCHA )
463+ )
456464 )
457- )
465+ await asyncio .sleep (WD_TIMEOUT_SHORT )
466+ try :
467+ driver .find_element (By .XPATH , XPATH_CAPTCHA )
468+ except :
469+ break # No element found, skip the loop to prevent pointless waiting
470+
458471 except TimeoutException as exc :
459472 raise TimeoutError ("CAPTCHA was not solved by the user" ) from exc
460473
0 commit comments