Skip to content

Commit afd20bc

Browse files
authored
Merge pull request #3441 from seleniumbase/cdp-mode-patch-26
CDP Mode - Patch 26
2 parents b12765b + 2d0a322 commit afd20bc

17 files changed

+236
-94
lines changed

examples/cdp_mode/ReadMe.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66

77
--------
88

9-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="https://github.com/user-attachments/assets/91e7ff7b-d155-4ba9-b17b-b097825fcf42" title="SeleniumBase on YouTube" width="350" /></a>
9+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="https://github.com/user-attachments/assets/91e7ff7b-d155-4ba9-b17b-b097825fcf42" title="SeleniumBase on YouTube" width="320" /></a>
1010
<p>(<b><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM">Watch the CDP Mode tutorial on YouTube! ▶️</a></b>)</p>
1111

1212
--------
1313

14-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U"><img src="https://github.com/user-attachments/assets/82ab2715-727e-4d09-9314-b8905795dc43" title="SeleniumBase on YouTube" width="350" /></a>
14+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U"><img src="https://github.com/user-attachments/assets/82ab2715-727e-4d09-9314-b8905795dc43" title="SeleniumBase on YouTube" width="320" /></a>
1515
<p>(<b><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U">Watch "Hacking websites with CDP" on YouTube! ▶️</a></b>)</p>
1616

1717
--------
1818

19+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=gEZhTfaIxHQ"><img src="https://github.com/user-attachments/assets/656977e1-5d66-4d1c-9eec-0aaa41f6522f" title="SeleniumBase on YouTube" width="320" /></a>
20+
<p>(<b><a href="https://www.youtube.com/watch?v=gEZhTfaIxHQ">Watch "Web-Scraping with GitHub Actions" on YouTube! ▶️</a></b>)</p>
21+
22+
--------
23+
1924
👤 <b translate="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 <b translate="no">CDP Mode</b> comes in.)
2025

2126
🐙 <b translate="no">CDP Mode</b> is based on <a href="https://github.com/HyperionGray/python-chrome-devtools-protocol" translate="no">python-cdp</a>, <a href="https://github.com/HyperionGray/trio-chrome-devtools-protocol" translate="no">trio-cdp</a>, and <a href="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 <code>Python-CDP</code> code is imported from <a href="https://github.com/mdmintz/MyCDP" translate="no">MyCDP</a>.)

examples/cdp_mode/raw_glassdoor.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, ad_block=True) as sb:
4+
url = "https://www.glassdoor.com/Reviews/index.htm"
5+
sb.activate_cdp_mode(url)
6+
sb.uc_gui_click_captcha()
7+
sb.highlight('[data-test="global-nav-glassdoor-logo"]')
8+
sb.highlight('[data-test="site-header-companies"]')
9+
sb.highlight('[data-test="search-button"]')
10+
sb.highlight('[data-test="sign-in-button"]')
11+
sb.highlight('[data-test="company-search-autocomplete"]')

examples/raw_invisible_captcha.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, incognito=True) as sb:
4+
url = "https://seleniumbase.io/apps/invisible_recaptcha"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(1)
7+
sb.assert_element("img#captcha-success", timeout=3)
8+
sb.set_messenger_theme(location="top_left")
9+
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/raw_recaptcha.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, incognito=True) as sb:
4-
url = "https://seleniumbase.io/apps/recaptcha"
5-
sb.activate_cdp_mode(url)
6-
sb.sleep(1)
7-
sb.uc_gui_handle_captcha() # Try with TAB + SPACEBAR
8-
sb.assert_element("img#captcha-success", timeout=3)
9-
sb.set_messenger_theme(location="top_left")
10-
sb.post_message("SeleniumBase wasn't detected", duration=3)
11-
123
with SB(uc=True, test=True, incognito=True) as sb:
134
url = "https://seleniumbase.io/apps/recaptcha"
145
sb.activate_cdp_mode(url)

examples/uc_cdp_events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rich.pretty import pprint
22
from seleniumbase import BaseCase
3-
BaseCase.main(__name__, __file__, "--uc", "--uc-cdp", "-s")
3+
BaseCase.main(__name__, __file__, "--uc", "--uc-cdp")
44

55

66
class CDPTests(BaseCase):

examples/verify_undetected.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Some sites use scripts to detect Selenium, and then block you.
33
To evade detection, add --uc as a pytest command-line option."""
44
from seleniumbase import BaseCase
5-
BaseCase.main(__name__, __file__, "--uc", "-s")
5+
BaseCase.main(__name__, __file__, "--uc")
66

77

88
class UndetectedTest(BaseCase):

help_docs/uc_mode.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
99
---
1010

11-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=5dMFI3e85ig"><img src="http://img.youtube.com/vi/5dMFI3e85ig/0.jpg" title="SeleniumBase on YouTube" width="350" /></a>
11+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=5dMFI3e85ig"><img src="http://img.youtube.com/vi/5dMFI3e85ig/0.jpg" title="SeleniumBase on YouTube" width="320" /></a>
1212
<p>(<b><a href="https://www.youtube.com/watch?v=5dMFI3e85ig">Watch the 1st UC Mode tutorial on YouTube! ▶️</a></b>)</p>
1313

1414
----
1515

16-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=2pTpBtaE7SQ"><img src="http://img.youtube.com/vi/2pTpBtaE7SQ/0.jpg" title="SeleniumBase on YouTube" width="350" /></a>
16+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=2pTpBtaE7SQ"><img src="http://img.youtube.com/vi/2pTpBtaE7SQ/0.jpg" title="SeleniumBase on YouTube" width="320" /></a>
1717
<p>(<b><a href="https://www.youtube.com/watch?v=2pTpBtaE7SQ">Watch the 2nd UC Mode tutorial on YouTube! ▶️</a></b>)</p>
1818

1919
----
2020

21-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=-EpZlhGWo9k"><img src="http://img.youtube.com/vi/-EpZlhGWo9k/0.jpg" title="SeleniumBase on YouTube" width="350" /></a>
21+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=-EpZlhGWo9k"><img src="http://img.youtube.com/vi/-EpZlhGWo9k/0.jpg" title="SeleniumBase on YouTube" width="320" /></a>
2222
<p>(<b><a href="https://www.youtube.com/watch?v=-EpZlhGWo9k">Watch the 3rd UC Mode tutorial on YouTube! ▶️</a></b>)</p>
2323

2424
----
2525

26-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="http://img.youtube.com/vi/Mr90iQmNsKM/0.jpg" title="SeleniumBase on YouTube" width="350" /></a>
26+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="http://img.youtube.com/vi/Mr90iQmNsKM/0.jpg" title="SeleniumBase on YouTube" width="320" /></a>
2727
<p>(<b><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM">Watch the 4th UC Mode tutorial on YouTube! ▶️</a></b>)</p>
2828

2929
----

integrations/docker/ReadMe.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ https://docs.docker.com/engine/install/
1414

1515
docker build -t seleniumbase .
1616

17-
If running on an Apple M1/M2 Mac, use this instead:
17+
**(NOTE) - If running on an Apple M1/M2 Mac, use this instead:**
1818

1919
docker build --platform linux/amd64 -t seleniumbase .
2020

21-
M1/M2 Mac users should also see [StackOverflow.com/a/76586216/7058266](https://stackoverflow.com/a/76586216/7058266) to **Enable Rosetta in Docker Desktop**. (Otherwise **you will** encounter errors like this when Chrome tries to launch: `"Chrome failed to start: crashed."`)
21+
**M1/M2 Mac users** should also see [StackOverflow.com/a/76586216/7058266](https://stackoverflow.com/a/76586216/7058266) to **Enable Rosetta in Docker Desktop**. (Otherwise **you will** encounter errors like this when Chrome tries to launch: `"Chrome failed to start: crashed."`)
2222

2323
#### 4. Run [the example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) with Chrome inside your Docker: (Once the test completes after a few seconds, you'll automatically exit the Docker shell)
2424

mkdocs_build/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ lxml==5.3.0
1818
pyquery==2.0.1
1919
readtime==3.0.0
2020
mkdocs==1.6.1
21-
mkdocs-material==9.5.49
21+
mkdocs-material==9.5.50
2222
mkdocs-exclude-search==0.6.6
2323
mkdocs-simple-hooks==0.1.5
2424
mkdocs-material-extensions==1.3.1

requirements.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ attrs>=24.3.0
77
certifi>=2024.12.14
88
exceptiongroup>=1.2.2
99
websockets~=13.1;python_version<"3.9"
10-
websockets>=14.1;python_version>="3.9"
11-
filelock>=3.16.1
10+
websockets>=14.2;python_version>="3.9"
11+
filelock~=3.16.1;python_version<"3.9"
12+
filelock>=3.17.0;python_version>="3.9"
1213
fasteners>=0.19
1314
mycdp>=1.1.0
1415
pynose>=1.5.3
@@ -41,7 +42,8 @@ trio==0.28.0;python_version>="3.9"
4142
trio-websocket==0.11.1
4243
wsproto==1.2.0
4344
websocket-client==1.8.0
44-
selenium==4.27.1
45+
selenium==4.27.1;python_version<"3.9"
46+
selenium==4.28.0;python_version>="3.9"
4547
cssselect==1.2.0
4648
sortedcontainers==2.4.0
4749
execnet==2.1.1

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.33.15"
2+
__version__ = "4.34.0"

0 commit comments

Comments
 (0)