Skip to content

Commit

Permalink
Added check for audio challenge appearing
Browse files Browse the repository at this point in the history
Added check for audio challenge appearing when solving the image challenge to ensure the image challenge is displayed.
  • Loading branch information
Xewdy444 committed Sep 19, 2023
1 parent 82d2042 commit 8dbf8b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
12 changes: 9 additions & 3 deletions playwright_recaptcha/recaptchav2/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions playwright_recaptcha/recaptchav2/recaptcha_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
9 changes: 6 additions & 3 deletions playwright_recaptcha/recaptchav2/sync_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8dbf8b7

Please sign in to comment.