Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
fix(account): Fixed check_captcha edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
GaspardCulis committed Aug 17, 2024
1 parent 754340a commit 73213fe
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/elevenlabs_unleashed/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import names
import requests
import undetected_chromedriver as uc
from selenium.common.exceptions import JavascriptException
from selenium.common.exceptions import JavascriptException, NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
Expand Down Expand Up @@ -175,20 +175,26 @@ def submit(self):
return super()

def check_captcha(self):
captcha_iframe = self.driver.find_element(By.XPATH, "//iframe[@tabindex='0']")
try:
captcha_iframe = self.driver.find_element(
By.XPATH, "//iframe[@tabindex='0']"
)

self.driver.switch_to.frame(captcha_iframe)
captcha_checkbox = self.wait.until(
lambda driver: driver.find_element(By.ID, "checkbox")
)
# Wait for aria-checked to be true
t0 = monotonic()
while captcha_checkbox.get_attribute("aria-checked") == "false":
sleep(0.1)
if monotonic() - t0 > 20:
raise Exception("Captcha not checked in time")
self.driver.switch_to.frame(captcha_iframe)
captcha_checkbox = self.wait.until(
lambda driver: driver.find_element(By.ID, "checkbox")
)
# Wait for aria-checked to be true
t0 = monotonic()
while captcha_checkbox.get_attribute("aria-checked") == "false":
sleep(0.1)
if monotonic() - t0 > 20:
raise Exception("Captcha not checked in time")

self.driver.switch_to.default_content()
except NoSuchElementException:
pass

self.driver.switch_to.default_content()
return self


Expand Down

0 comments on commit 73213fe

Please sign in to comment.