Skip to content

Commit 12bbad0

Browse files
authored
fix: support official reCAPTCHA demo
* fix: support standard reCAPTCHA demo markup * docs: add ready-to-run reCAPTCHA demo
1 parent 77c99c8 commit 12bbad0

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,19 @@ CAPTCHA_API_KEY=your_api_key
7474
TARGET_URL=https://your-site.example/captcha-page
7575
```
7676

77-
> Before running an example, replace `TARGET_URL` with the target page for your
78-
> own authorized test. Do not leave the placeholder value. Each example expects
79-
> the page to contain the corresponding captcha type and may require its
80-
> selectors or callback names to be adjusted for that page.
77+
> Before running an example other than `recaptcha_v2.py`, replace `TARGET_URL`
78+
> with the target page for your own authorized test. Do not leave the placeholder
79+
> value. Each example expects the page to contain the corresponding captcha type
80+
> and may require its selectors or callback names to be adjusted for that page.
81+
82+
The reCAPTCHA v2 example is ready to run without setting `TARGET_URL`:
83+
84+
```bash
85+
python examples/recaptcha_v2.py
86+
```
87+
88+
It uses the official public reCAPTCHA demo by default. Set `TARGET_URL` only if
89+
you want to run it against another authorized page.
8190

8291
Run an example from the repository root:
8392

‎examples/recaptcha_v2.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
"""Solve reCAPTCHA v2 in a SeleniumBase browser session."""
22

3+
import os
34
import time
45

56
from captcha_solver_api.tasks import RecaptchaV2TaskProxyless
6-
from common import create_client, fill_response_field, required_env, show_success, wait_for_xpath
7+
from common import (
8+
create_client,
9+
fill_response_field,
10+
wait_for_css,
11+
wait_for_xpath,
12+
)
713
from seleniumbase import Driver
814

9-
URL = required_env("TARGET_URL")
10-
SITEKEY_LOCATOR = "//div[@id='g-recaptcha']"
11-
SUBMIT_LOCATOR = "//button[@data-action='demo_action']"
15+
URL = os.getenv("TARGET_URL") or "https://www.google.com/recaptcha/api2/demo"
16+
SITEKEY_LOCATOR = "//*[@data-sitekey]"
17+
SUBMIT_LOCATOR = "//*[@type='submit']"
18+
SUCCESS_SELECTOR = ".recaptcha-success, p.successMessage"
1219

1320

1421
def main() -> None:
@@ -28,7 +35,7 @@ def main() -> None:
2835
)
2936
fill_response_field(driver, "g-recaptcha-response", solution["gRecaptchaResponse"])
3037
wait_for_xpath(driver, SUBMIT_LOCATOR).click()
31-
show_success(driver)
38+
print(wait_for_css(driver, SUCCESS_SELECTOR).text)
3239
time.sleep(5)
3340

3441

0 commit comments

Comments
 (0)