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
Copy file name to clipboardExpand all lines: examples/cdp_mode/ReadMe.md
+43-7Lines changed: 43 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
👤 <btranslate="no">UC Mode</b> avoids bot-detection by first disconnecting WebDriver from the browser at strategic times, calling special <code>PyAutoGUI</code> methods to bypass CAPTCHAs (as needed), and finally reconnecting the <code>driver</code> afterwards so that WebDriver actions can be performed again. Although this approach works for bypassing simple CAPTCHAs, more flexibility is needed for bypassing bot-detection on websites with advanced protection. (That's where <btranslate="no">CDP Mode</b> comes in.)
8
8
9
-
🐙 <btranslate="no">CDP Mode</b> is based on <ahref="https://github.com/HyperionGray/python-chrome-devtools-protocol"translate="no">python-cdp</a>, <ahref="https://github.com/HyperionGray/trio-chrome-devtools-protocol"translate="no">trio-cdp</a>, and <ahref="https://github.com/ultrafunkamsterdam/nodriver"translate="no">nodriver</a>. <code>trio-cdp</code> was an early implementation of <code>python-cdp</code>, whereas <code>nodriver</code> is a modern implementation of <code>python-cdp</code>. (Refactored CDP code is imported from <ahref="https://github.com/mdmintz/MyCDP"translate="no">MyCDP</a>.)
9
+
🐙 <btranslate="no">CDP Mode</b> is based on <ahref="https://github.com/HyperionGray/python-chrome-devtools-protocol"translate="no">python-cdp</a>, <ahref="https://github.com/HyperionGray/trio-chrome-devtools-protocol"translate="no">trio-cdp</a>, and <ahref="https://github.com/ultrafunkamsterdam/nodriver"translate="no">nodriver</a>. <code>trio-cdp</code> is an early implementation of <code>python-cdp</code>, and <code>nodriver</code> is a modern implementation of <code>python-cdp</code>. (Refactored Python-CDP code is imported from <ahref="https://github.com/mdmintz/MyCDP"translate="no">MyCDP</a>.)
10
10
11
11
🐙 <btranslate="no">CDP Mode</b> includes multiple updates to the above, such as:
That disconnects WebDriver from Chrome (which prevents detection), and gives you access to `sb.cdp` methods (which don't trigger anti-bot checks).
29
+
30
+
### 🐙 Here are some common `sb.cdp` methods:
31
+
32
+
*`sb.cdp.click(selector)`
33
+
*`sb.cdp.click_if_visible(selector)`
34
+
*`sb.cdp.type(selector, text)`
35
+
*`sb.cdp.press_keys(selector, text)`
36
+
*`sb.cdp.select_all(selector)`
37
+
*`sb.cdp.get_text(selector)`
38
+
39
+
When `type()` is too fast, use the slower `press_keys()` to avoid detection. You can also use `sb.sleep(seconds)` to slow things down.
40
+
41
+
To use WebDriver methods again, call:
42
+
43
+
***`sb.reconnect()`** or **`sb.connect()`**
44
+
45
+
(Note that reconnecting allows anti-bots to detect you, so only reconnect if it is safe to do so.)
46
+
47
+
To disconnect again, call:
48
+
49
+
***`sb.disconnect()`**
50
+
51
+
While disconnected, if you accidentally call a WebDriver method, then SeleniumBase will attempt to use the CDP Mode version of that method (if available). For example, if you accidentally call `sb.click(selector)` instead of `sb.cdp.click(selector)`, then your WebDriver call will automatically be redirected to the CDP Mode version. Not all WebDriver methods have a matching CDP Mode method. In that scenario, calling a WebDriver method while disconnected could raise an error, or make WebDriver automatically reconnect first.
52
+
53
+
To find out if WebDriver is connected or disconnected, call:
54
+
55
+
***`sb.is_connected()`**
56
+
28
57
--------
29
58
30
59
### 🐙 <btranslate="no">CDP Mode</b> examples:
@@ -45,13 +74,15 @@ from seleniumbase import SB
45
74
with SB(uc=True, test=True, locale_code="en") as sb:
0 commit comments