diff --git a/README.md b/README.md index 8fd84a7fdb4..d315e2ec506 100755 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ with SB(test=True) as sb: -------- -

📗 Here's an example of bypassing bot-detection on a site that uses Cloudflare: SeleniumBase/examples/cdp_mode/raw_gitlab.py

+

📗 Here's an example of bypassing Cloudflare's challenge page: SeleniumBase/examples/cdp_mode/raw_gitlab.py

```python from seleniumbase import SB @@ -93,8 +93,8 @@ from seleniumbase import SB with SB(uc=True, test=True, locale_code="en") as sb: url = "https://gitlab.com/users/sign_in" sb.activate_cdp_mode(url) - sb.uc_gui_click_captcha() # PyAutoGUI if needed - sb.save_screenshot_to_logs() + sb.uc_gui_click_captcha() + sb.sleep(2) ``` @@ -827,7 +827,7 @@ You can run it from the ``examples/`` folder like this: pytest test_fail.py ``` -🔵 You'll notice that a logs folder, "latest_logs", was created to hold information about the failing test, and screenshots. During test runs, past results get moved to the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), or if your run tests with ``--archive-logs``. If you choose not to archive existing logs, they will be deleted and replaced by the logs of the latest test run. +🔵 You'll notice that a logs folder, ``./latest_logs/``, was created to hold information (and screenshots) about the failing test. During test runs, past results get moved to the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), or if your run tests with ``--archive-logs``. If you choose not to archive existing logs, they will be deleted and replaced by the logs of the latest test run. -------- diff --git a/examples/cdp_mode/ReadMe.md b/examples/cdp_mode/ReadMe.md index ddef88e9100..c7031b8e4f5 100644 --- a/examples/cdp_mode/ReadMe.md +++ b/examples/cdp_mode/ReadMe.md @@ -35,38 +35,45 @@ That disconnects WebDriver from Chrome (which prevents detection), and gives you access to `sb.cdp` methods (which don't trigger anti-bot checks). -Simple example: ([SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py)) +Simple example: ([SeleniumBase/examples/cdp_mode/raw_gitlab.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py)) ```python from seleniumbase import SB -with SB(uc=True, test=True) as sb: - url = "www.planetminecraft.com/account/sign_in/" +with SB(uc=True, test=True, locale_code="en") as sb: + url = "https://gitlab.com/users/sign_in" sb.activate_cdp_mode(url) - sb.sleep(2) - sb.cdp.gui_click_element("#turnstile-widget div") + sb.uc_gui_click_captcha() sb.sleep(2) ``` - + -(If the CAPTCHA wasn't initially bypassed, then the click gets the job done.) +(If the CAPTCHA wasn't bypassed automatically, then `sb.uc_gui_click_captcha()` gets the job done.) -Note that `PyAutoGUI` is an optional dependency. If calling a method that uses it when not already installed, then `SeleniumBase` will install it at run-time, which pauses the script briefly. +Note that `PyAutoGUI` is an optional dependency. If calling a method that uses it when not already installed, then `SeleniumBase` installs `PyAutoGUI` at run-time. + +-------- -For standard Cloudflare pages, use `sb.uc_gui_click_captcha()` if Turnstiles aren't initially bypassed. Example: ([SeleniumBase/examples/cdp_mode/raw_gitlab.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py)) +For Cloudflare CAPTCHAs that appear as part of a websites, you may need to use `sb.cdp.gui_click_element(selector)` instead (if the Turnstile wasn't bypassed automatically). Example: ([SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py)) ```python from seleniumbase import SB -with SB(uc=True, test=True, locale_code="en") as sb: - url = "https://gitlab.com/users/sign_in" +with SB(uc=True, test=True) as sb: + url = "www.planetminecraft.com/account/sign_in/" sb.activate_cdp_mode(url) - sb.uc_gui_click_captcha() + sb.sleep(2) + sb.cdp.gui_click_element("#turnstile-widget div") sb.sleep(2) ``` - + + +When using `sb.cdp.gui_click_element(selector)` on CF Turnstiles, use the parent `selector` that appears **above** the `#shadow-root` element: +Eg. `sb.cdp.gui_click_element("#turnstile-widget div")` + + --------