You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple example from [SeleniumBase/examples/cdp_mode/raw_gitlab.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py):
(If the CAPTCHA wasn't bypassed automatically, then `sb.uc_gui_click_captcha()` gets the job done.)
62
+
(If the CAPTCHA wasn't bypassed automatically when going to the URL, then `sb.uc_gui_click_captcha()` gets the job done with a mouse click from [PyAutoGUI](https://github.com/asweigart/pyautogui).)
64
63
65
-
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.
64
+
ℹ️ 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.
66
65
67
66
--------
68
67
69
-
For some Cloudflare CAPTCHAs that appear within 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))
68
+
You can also use `sb.cdp.gui_click_element(selector)`to click on elements using `PyAutoGUI`. (This is useful when clicking inside `#shadow-root`.) Example:
In most cases, `sb.uc_gui_click_captcha()` is good enough for CF Turnstiles without needing `sb.cdp.gui_click_element(selector)`. (See [SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py))
89
+
89
90
--------
90
91
91
92
### 🐙 Here are a few common `sb.cdp` methods:
92
93
93
94
*`sb.cdp.click(selector)` (Uses the CDP API to click)
94
-
*`sb.cdp.click_if_visible(selector)`
95
+
*`sb.cdp.click_if_visible(selector)` (Click if visible)
ℹ️ When available, calling `sb.METHOD()` redirects to `sb.cdp.METHOD()` because regular SB methods automatically call their CDP Mode counterparts to maintain stealth when CDP Mode is active.
<btranslate="no">Pure CDP Mode</b> doesn't use WebDriver for anything. The browser is launched using CDP, and all browser actions are performed using CDP (or <code>PyAutoGUI</code>). Initialization:
530
+
531
+
```python
532
+
from seleniumbase import sb_cdp
533
+
534
+
sb = sb_cdp.Chrome(url=None, **kwargs)
535
+
```
536
+
537
+
<btranslate="no">Pure CDP Mode</b> includes all methods from regular CDP Mode, except that they're called directly from <code>sb</code> instead of <code>sb.cdp</code>. Eg: <code>sb.gui_click_captcha()</code>. To quit a CDP-launched browser, use `sb.driver.stop()`.
538
+
539
+
Basic example from [SeleniumBase/examples/cdp_mode/raw_cdp_turnstile.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_cdp_turnstile.py):
540
+
541
+
```python
542
+
from seleniumbase import sb_cdp
543
+
544
+
url ="https://seleniumbase.io/apps/turnstile"
545
+
sb = sb_cdp.Chrome(url)
546
+
sb.gui_click_captcha()
547
+
sb.sleep(2)
548
+
sb.driver.stop()
549
+
```
550
+
551
+
Another example: ([SeleniumBase/examples/cdp_mode/raw_cdp_methods.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_cdp_methods.py))
552
+
553
+
```python
554
+
from seleniumbase import sb_cdp
555
+
556
+
url ="https://seleniumbase.io/demo_page"
557
+
sb = sb_cdp.Chrome(url)
558
+
sb.press_keys("input", "Text")
559
+
sb.highlight("button")
560
+
sb.type("textarea", "Here are some words")
561
+
sb.click("button")
562
+
sb.set_value("input#mySlider", "100")
563
+
sb.click_visible_elements("input.checkBoxClassB")
564
+
sb.select_option_by_text("#mySelect", "Set to 75%")
0 commit comments