|
35 | 35 |
|
36 | 36 | That disconnects WebDriver from Chrome (which prevents detection), and gives you access to `sb.cdp` methods (which don't trigger anti-bot checks).
|
37 | 37 |
|
38 |
| -Simple example: ([SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py)) |
| 38 | +Simple example: ([SeleniumBase/examples/cdp_mode/raw_gitlab.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py)) |
39 | 39 |
|
40 | 40 | ```python
|
41 | 41 | from seleniumbase import SB
|
42 | 42 |
|
43 |
| -with SB(uc=True, test=True) as sb: |
44 |
| - url = "www.planetminecraft.com/account/sign_in/" |
| 43 | +with SB(uc=True, test=True, locale_code="en") as sb: |
| 44 | + url = "https://gitlab.com/users/sign_in" |
45 | 45 | sb.activate_cdp_mode(url)
|
46 |
| - sb.sleep(2) |
47 |
| - sb.cdp.gui_click_element("#turnstile-widget div") |
| 46 | + sb.uc_gui_click_captcha() |
48 | 47 | sb.sleep(2)
|
49 | 48 | ```
|
50 | 49 |
|
51 |
| -<img src="https://seleniumbase.github.io/other/planet_mc.png" title="SeleniumBase" width="480"> |
| 50 | +<img src="https://seleniumbase.github.io/other/cf_sec.jpg" title="SeleniumBase" width="332"> <img src="https://seleniumbase.github.io/other/gitlab_bypass.png" title="SeleniumBase" width="288"> |
52 | 51 |
|
53 |
| -(If the CAPTCHA wasn't initially bypassed, then the click gets the job done.) |
| 52 | +(If the CAPTCHA wasn't bypassed automatically, then `sb.uc_gui_click_captcha()` gets the job done.) |
54 | 53 |
|
55 |
| -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. |
| 54 | +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. |
| 55 | + |
| 56 | +-------- |
56 | 57 |
|
57 |
| -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)) |
| 58 | +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)) |
58 | 59 |
|
59 | 60 | ```python
|
60 | 61 | from seleniumbase import SB
|
61 | 62 |
|
62 |
| -with SB(uc=True, test=True, locale_code="en") as sb: |
63 |
| - url = "https://gitlab.com/users/sign_in" |
| 63 | +with SB(uc=True, test=True) as sb: |
| 64 | + url = "www.planetminecraft.com/account/sign_in/" |
64 | 65 | sb.activate_cdp_mode(url)
|
65 |
| - sb.uc_gui_click_captcha() |
| 66 | + sb.sleep(2) |
| 67 | + sb.cdp.gui_click_element("#turnstile-widget div") |
66 | 68 | sb.sleep(2)
|
67 | 69 | ```
|
68 | 70 |
|
69 |
| -<img src="https://seleniumbase.github.io/other/cf_sec.jpg" title="SeleniumBase" width="404"> <img src="https://seleniumbase.github.io/other/gitlab_bypass.png" title="SeleniumBase" width="350"> |
| 71 | +<img src="https://seleniumbase.github.io/other/planet_mc.png" title="SeleniumBase" width="480"> |
| 72 | + |
| 73 | +When using `sb.cdp.gui_click_element(selector)` on CF Turnstiles, use the parent `selector` that appears **above** the `#shadow-root` element: |
| 74 | +Eg. `sb.cdp.gui_click_element("#turnstile-widget div")` |
| 75 | + |
| 76 | +<img src="https://seleniumbase.github.io/other/above_shadow.png" title="SeleniumBase" width="480"> |
70 | 77 |
|
71 | 78 | --------
|
72 | 79 |
|
|
0 commit comments