Skip to content

Commit 115bb62

Browse files
authored
Merge pull request #4072 from seleniumbase/cdp-mode-patch-71
CDP Mode: Patch 71
2 parents 1cc6b08 + a798ffe commit 115bb62

File tree

16 files changed

+108
-135
lines changed

16 files changed

+108
-135
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
<br />
5555
</p>
5656

57-
<p>SeleniumBase is a browser automation framework for the modern web. Both new and experienced Python users alike can easily get started. With special stealth features like UC Mode and CDP Mode, you'll be evading bot-detection and bypassing CAPTCHAs in minutes.</p>
57+
<p>SeleniumBase is a browser automation framework that empowers software teams to innovate faster and handle modern web challenges with ease. With stealth options like CDP Mode, you'll avoid the usual restrictions imposed by websites deploying bot-detection services.</p>
5858

5959
--------
6060

6161
📚 Learn from [**over 200 examples** in the **SeleniumBase/examples/** folder](https://github.com/seleniumbase/SeleniumBase/tree/master/examples).
6262

63-
🐙 Stealth modes: <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"><b>UC Mode</b></a> and <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><b>CDP Mode</b></a> help you evade bot-detection.
63+
🐙 Stealth modes: <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"><b>UC Mode</b></a> and <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><b>CDP Mode</b></a> can bypass bot-detection, solve CAPTCHAs, and call advanced methods from the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a>.
6464

65-
ℹ️ Most scripts run with raw <code translate="no"><b>python</b></code>, although some scripts use <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> that expect <a href="https://docs.pytest.org/en/latest/how-to/usage.html" translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover, collect, and run tests automatically).
65+
ℹ️ Many examples run with raw <code translate="no"><b>python</b></code>, although some use <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> that expect <a href="https://docs.pytest.org/en/latest/how-to/usage.html" translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover, collect, and run tests automatically).
6666

6767
--------
6868

examples/cdp_mode/ReadMe.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32">](https://github.com/seleniumbase/SeleniumBase/) CDP Mode 🐙
44

5-
🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> is a stealth mode of SeleniumBase that uses the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no"><span translate="no">Chrome Devtools Protocol</span></a> (via <a href="https://github.com/mdmintz/MyCDP" translate="no"><span translate="no">MyCDP</span></a>) to control the web browser. <b translate="no">CDP Mode</b> can be used either as a subset of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">SeleniumBase UC Mode</span></a></b>, or via <b><a href="#Pure_CDP_Mode" translate="no">Pure CDP Mode</a></b> (<code>sb_cdp</code>), which doesn't use WebDriver at all, and has a slightly different setup.
5+
🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> is a stealth mode of SeleniumBase that uses the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a> (via <a href="https://github.com/mdmintz/MyCDP" translate="no"><span translate="no">MyCDP</span></a>) to control the web browser. <b translate="no">CDP Mode</b> can be used either as a subset of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">SeleniumBase UC Mode</span></a></b>, or via <b><a href="#Pure_CDP_Mode" translate="no">Pure CDP Mode</a></b> (<code>sb_cdp</code>), which doesn't use WebDriver at all, and has a slightly different setup.
66

77
--------
88

@@ -55,6 +55,7 @@ with SB(uc=True, test=True, locale="en") as sb:
5555
sb.activate_cdp_mode(url)
5656
sb.sleep(2)
5757
sb.solve_captcha()
58+
sb.sleep(2)
5859
```
5960

6061
<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">
@@ -63,7 +64,7 @@ with SB(uc=True, test=True, locale="en") as sb:
6364

6465
--------
6566

66-
`sb.cdp.gui_click_element(selector)` lets you click on elements using `PyAutoGUI`. Example:
67+
You can also use `PyAutoGUI` to click on elements with the mouse by calling `sb.cdp.gui_click_element(selector)`. Example:
6768

6869
```python
6970
from seleniumbase import SB
@@ -86,7 +87,7 @@ Eg. `sb.cdp.gui_click_element("#turnstile-widget div")`
8687

8788
In most cases, `sb.solve_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))
8889

89-
ℹ️ 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.
90+
ℹ️ Note that `PyAutoGUI` is an optional dependency. If calling a method that uses it when not already installed, then `SeleniumBase` installs `PyAutoGUI` at runtime.
9091

9192
--------
9293

examples/cdp_mode/raw_albertsons.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.5)
77
sb.remove_element("div > div > article")
8-
sb.cdp.scroll_into_view('input[type="search"]')
8+
sb.scroll_into_view('input[type="search"]')
99
close_btn = ".notification-alert-wrapper__close-button"
10-
sb.cdp.click_if_visible(close_btn)
11-
sb.cdp.click("input#search-suggestion-input")
10+
sb.click_if_visible(close_btn)
11+
sb.click("input#search-suggestion-input")
1212
sb.sleep(0.2)
1313
search = "Avocado Smoked Salmon"
1414
required_text = "Salmon"
15-
sb.cdp.press_keys("input#search-suggestion-input", search)
15+
sb.press_keys("input#search-suggestion-input", search)
1616
sb.sleep(0.8)
17-
sb.cdp.click("#suggestion-0 a span")
17+
sb.click("#suggestion-0 a span")
1818
sb.sleep(0.8)
19-
sb.cdp.click_if_visible(close_btn)
20-
sb.sleep(2.8)
19+
sb.click_if_visible(close_btn)
20+
sb.sleep(3.2)
2121
print('*** Albertsons Search for "%s":' % search)
2222
print(' (Results must contain "%s".)' % required_text)
2323
unique_item_text = []
2424
item_selector = 'a[href*="/meal-plans-recipes/shop/"]'
25-
items = sb.cdp.find_elements(item_selector)
25+
items = sb.find_elements(item_selector)
2626
for item in items:
2727
sb.sleep(0.06)
2828
if required_text in item.text:

examples/cdp_mode/raw_cdp_copilot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from seleniumbase import sb_cdp
22

33
url = "https://copilot.microsoft.com/"
4-
sb = sb_cdp.Chrome(url, locale="en", guest=True)
4+
sb = sb_cdp.Chrome(url, locale="en")
55
textarea = "textarea#userInput"
66
sb.wait_for_element(textarea)
77
sb.sleep(1.5)

examples/cdp_mode/raw_cf_clearance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_cf_clearance_cookie(sb):
1212
url = "https://gitlab.com/users/sign_in"
1313
sb = sb_cdp.Chrome(url, incognito=True)
1414
sb.sleep(2.2) # Wait for CAPTCHA to load
15-
sb.gui_click_captcha() # (Only if found)
15+
sb.solve_captcha() # (Only if found)
1616
sb.sleep(2.2) # Wait for CAPTCHA success
1717
cf_cookie = get_cf_clearance_cookie(sb)
1818
if cf_cookie:

examples/cdp_mode/raw_copilot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, guest=True) as sb:
3+
with SB(uc=True, test=True, locale="en") as sb:
44
url = "https://copilot.microsoft.com/"
55
sb.activate_cdp_mode(url)
66
textarea = "textarea#userInput"

examples/cdp_mode/raw_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
url = "www.planetminecraft.com/account"
77
driver.uc_activate_cdp_mode(url)
88
driver.sleep(1)
9-
driver.cdp.solve_captcha()
9+
driver.solve_captcha()
1010
driver.wait_for_element_absent("input[disabled]")
1111
driver.sleep(2)

examples/cdp_mode/raw_elal.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
url = "www.elal.com/flight-deals/en-us/flights-from-boston-to-tel-aviv"
77
sb.activate_cdp_mode(url)
88
sb.sleep(3)
9-
sb.cdp.click('label:contains("Departure date")')
9+
sb.click('label:contains("Departure date")')
1010
sb.sleep(1)
1111
today = datetime.date.today()
1212
days_ahead = (4 - today.weekday() + 7) % 7
@@ -25,21 +25,21 @@
2525
sb.sleep(1)
2626
sb.cdp.gui_press_keys("\b" * 10 + formatted_date + "\n")
2727
sb.sleep(1)
28-
sb.cdp.click('button[data-att="done"]')
28+
sb.click('button[data-att="done"]')
2929
sb.sleep(1)
30-
sb.cdp.click('button[data-att="search"]')
30+
sb.click('button[data-att="search"]')
3131
sb.sleep(5)
32-
sb.cdp.click_if_visible("#onetrust-close-btn-container button")
32+
sb.click_if_visible("#onetrust-close-btn-container button")
3333
sb.sleep(1)
3434
view_other_dates = 'button[aria-label*="viewOtherDates.cta"]'
35-
if sb.cdp.is_element_visible(view_other_dates):
36-
sb.cdp.click(view_other_dates)
35+
if sb.is_element_visible(view_other_dates):
36+
sb.click(view_other_dates)
3737
sb.sleep(5)
3838
if sb.is_element_visible("flexible-search-calendar"):
3939
print("*** Flight Calendar for El Al (Boston to Tel Aviv): ***")
40-
print(sb.cdp.get_text("flexible-search-calendar"))
40+
print(sb.get_text("flexible-search-calendar"))
4141
prices = []
42-
elements = sb.cdp.find_elements("span.matric-cell__content__price")
42+
elements = sb.find_elements("span.matric-cell__content__price")
4343
if elements:
4444
print("*** Prices List: ***")
4545
for element in elements:
@@ -50,32 +50,32 @@
5050
print("*** Lowest Price: ***")
5151
lowest_price = prices[0]
5252
print(lowest_price)
53-
sb.cdp.scroll_down(12)
53+
sb.scroll_down(12)
5454
sb.sleep(1)
55-
sb.cdp.find_element_by_text(lowest_price).click()
55+
sb.find_element_by_text(lowest_price).click()
5656
sb.sleep(2)
5757
search_cell = 'button[aria-label*="Search.cell.buttonTitle"]'
58-
sb.cdp.scroll_into_view(search_cell)
58+
sb.scroll_into_view(search_cell)
5959
sb.sleep(1)
60-
sb.cdp.click(search_cell)
60+
sb.click(search_cell)
6161
sb.sleep(5)
6262
else:
6363
print("*** Lowest Prices: ***")
6464
departure_prices = "#uiFlightPanel0 div.ui-bound__price__value"
6565
return_prices = "#uiFlightPanel1 div.ui-bound__price__value"
66-
elements = sb.cdp.find_elements(departure_prices)
66+
elements = sb.find_elements(departure_prices)
6767
for element in elements:
6868
if "lowest price" in element.text:
6969
print("Departure Flight:")
7070
print(element.text)
7171
break
72-
elements = sb.cdp.find_elements(return_prices)
72+
elements = sb.find_elements(return_prices)
7373
for element in elements:
7474
if "lowest price" in element.text:
7575
print("Return Flight:")
7676
print(element.text)
7777
break
78-
dates = sb.cdp.find_elements('div[class*="flight-date"]')
78+
dates = sb.find_elements('div[class*="flight-date"]')
7979
if len(dates) == 2:
8080
print("*** Departure Date: ***")
8181
print(dates[0].text)

examples/cdp_mode/raw_nordstrom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
url = "https://www.nordstrom.com/"
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.2)
7-
sb.cdp.click("input#keyword-search-input")
7+
sb.click("input#keyword-search-input")
88
sb.sleep(0.8)
99
search = "cocktail dresses for women teal"
10-
sb.cdp.press_keys("input#keyword-search-input", search + "\n")
10+
sb.press_keys("input#keyword-search-input", search + "\n")
1111
sb.sleep(2.2)
1212
for i in range(17):
13-
sb.cdp.scroll_down(16)
13+
sb.scroll_down(16)
1414
sb.sleep(0.14)
1515
print('*** Nordstrom Search for "%s":' % search)
1616
unique_item_text = []
17-
items = sb.cdp.find_elements("article")
17+
items = sb.find_elements("article")
1818
for item in items:
1919
description = item.querySelector("article h3")
2020
if description and description.text not in unique_item_text:

0 commit comments

Comments
 (0)