Skip to content

Commit 67b7801

Browse files
committed
web captcha
1 parent b0a4641 commit 67b7801

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

docs/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Glossary
3737
Releases
3838
---------------------
3939

40+
|UNRELEASED| v2.10.4
41+
======================
42+
- Fixed prematurely exiting when waiting for captcha to be completed by user.
43+
44+
4045
v2.10.3
4146
======================
4247
- Fixed Chrome driver not working with newer Chrome versions (115+).

src/daf/web.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class GLOBALS:
6969
WD_FETCH_INVITE_CLOUDFLARE_TRIES = 3
7070
WD_FETCH_INVITE_CLOUDFLARE_DELAY = 7
7171

72+
WD_CAPTCHA_RETRIES = 3
73+
7274
WD_RD_CLICK_UPPER_N = 5
7375
WD_RD_CLICK_LOWER_N = 2
7476
WD_OUTPUT_PATH = pathlib.Path.home().joinpath("daf/daf_web_data")
@@ -83,6 +85,9 @@ class GLOBALS:
8385
TOP_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")
8792
class 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

Comments
 (0)