From 8dbf8b7f5ab3ba10ea3c1e90d8f4304fff8aa54d Mon Sep 17 00:00:00 2001 From: Xewdy <95155966+Xewdy444@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:59:01 -0500 Subject: [PATCH] Added check for audio challenge appearing Added check for audio challenge appearing when solving the image challenge to ensure the image challenge is displayed. --- playwright_recaptcha/recaptchav2/async_solver.py | 12 +++++++++--- playwright_recaptcha/recaptchav2/recaptcha_box.py | 5 +++++ playwright_recaptcha/recaptchav2/sync_solver.py | 9 ++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/playwright_recaptcha/recaptchav2/async_solver.py b/playwright_recaptcha/recaptchav2/async_solver.py index b7d7da7..fec014c 100644 --- a/playwright_recaptcha/recaptchav2/async_solver.py +++ b/playwright_recaptcha/recaptchav2/async_solver.py @@ -348,9 +348,6 @@ async def _get_audio_url(self, recaptcha_box: AsyncRecaptchaBox) -> str: RecaptchaRateLimitError If the reCAPTCHA rate limit has been exceeded. """ - if await recaptcha_box.audio_challenge_button.is_visible(): - await recaptcha_box.audio_challenge_button.click(force=True) - while True: if await recaptcha_box.rate_limit_is_visible(): raise RecaptchaRateLimitError @@ -607,6 +604,15 @@ async def solve_recaptcha( elif await recaptcha_box.rate_limit_is_visible(): raise RecaptchaRateLimitError + if image_challenge and await recaptcha_box.image_challenge_button.is_visible(): + await recaptcha_box.image_challenge_button.click(force=True) + + if ( + not image_challenge + and await recaptcha_box.audio_challenge_button.is_visible() + ): + await recaptcha_box.audio_challenge_button.click(force=True) + if image_challenge and self._payload_response is None: image = recaptcha_box.image_challenge.locator("img").first image_url = await image.get_attribute("src") diff --git a/playwright_recaptcha/recaptchav2/recaptcha_box.py b/playwright_recaptcha/recaptchav2/recaptcha_box.py index e30db3e..7053b55 100644 --- a/playwright_recaptcha/recaptchav2/recaptcha_box.py +++ b/playwright_recaptcha/recaptchav2/recaptcha_box.py @@ -128,6 +128,11 @@ def audio_challenge_button(self) -> Locator: """The reCAPTCHA audio challenge button locator.""" return self.bframe_frame.get_by_role("button", name="Get an audio challenge") + @property + def image_challenge_button(self) -> Locator: + """The reCAPTCHA image challenge button locator.""" + return self.bframe_frame.get_by_role("button", name="Get a visual challenge") + @property def new_challenge_button(self) -> Locator: """The reCAPTCHA new challenge button locator.""" diff --git a/playwright_recaptcha/recaptchav2/sync_solver.py b/playwright_recaptcha/recaptchav2/sync_solver.py index 6049548..ef44a90 100644 --- a/playwright_recaptcha/recaptchav2/sync_solver.py +++ b/playwright_recaptcha/recaptchav2/sync_solver.py @@ -326,9 +326,6 @@ def _get_audio_url(self, recaptcha_box: SyncRecaptchaBox) -> str: RecaptchaRateLimitError If the reCAPTCHA rate limit has been exceeded. """ - if recaptcha_box.audio_challenge_button.is_visible(): - recaptcha_box.audio_challenge_button.click(force=True) - while True: if recaptcha_box.rate_limit_is_visible(): raise RecaptchaRateLimitError @@ -580,6 +577,12 @@ def solve_recaptcha( elif recaptcha_box.rate_limit_is_visible(): raise RecaptchaRateLimitError + if image_challenge and recaptcha_box.image_challenge_button.is_visible(): + recaptcha_box.image_challenge_button.click(force=True) + + if not image_challenge and recaptcha_box.audio_challenge_button.is_visible(): + recaptcha_box.audio_challenge_button.click(force=True) + if image_challenge and self._payload_response is None: image = recaptcha_box.image_challenge.locator("img").first image_url = image.get_attribute("src")