Skip to content

Commit b9fcffd

Browse files
authored
Merge pull request #4522 from seleniumbase/dependencies-and-examples
Refresh Dependencies and Examples
2 parents 8bc524c + 3b2a41d commit b9fcffd

15 files changed

Lines changed: 93 additions & 115 deletions

‎README.md‎

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
<meta property="og:image" content="https://seleniumbase.github.io/cdn/img/mac_sb_logo_5b.png" />
99
<link rel="icon" href="https://seleniumbase.github.io/img/logo7.png" />
1010

11-
<h1>SeleniumBase</h1>
12-
13-
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/nice_logo_8t.png" alt="SeleniumBase" width="424" /></a></p>
11+
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/nice_logo_8t.png" alt="SeleniumBase" width="400" /></a></p>
1412

1513
<p align="center" class="hero__title"><b>All-in-one Browser Automation Framework:<br />Web Crawling / Testing / Scraping / Stealth</b></p>
1614

@@ -52,21 +50,17 @@
5250
<br />
5351
</p>
5452

55-
📊 <a href="https://github.com/seleniumbase/SeleniumBase/"><b translate="no">SeleniumBase</b></a> is a complete framework for browser automation and testing with Python and <a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a>. Includes stealth options and other advanced features.
56-
57-
🐙 Stealth modes: <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md">UC Mode</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, handle CAPTCHAs, and call methods from the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a>. CDP Mode includes <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md"><b><span translate="no">Stealthy Playwright Mode</span></b></a>, which makes Playwright stealthy.
58-
59-
📚 The [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder includes over 100 ready-to-run examples. Examples that start with `test_` or end with `_test.py`/`_tests.py` are specifically designed to run with `pytest`. Other examples run directly with raw `python` (those files generally start with `raw_` to avoid confusion).
53+
--------
6054

61-
🥷 Stealthy examples are located in [SeleniumBase/examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
55+
🥷 Stealth modes: <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"><b>UC Mode</b></a> / <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, handle CAPTCHAs, and call methods from the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a>. CDP Mode includes <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md"><b><span translate="no">Stealthy Playwright Mode</span></b></a>, which makes Playwright stealthy.
6256

63-
--------
57+
🧪 End-to-End Testing examples are located in [./examples/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples).
6458

65-
<h3 align="left">⚙️ Stealthy architecture flowchart:</h3>
59+
🐙 CDP Mode (stealth) examples are located in [./examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
6660

67-
<img src="https://seleniumbase.github.io/other/sb_stealth.png" width="640" style="max-width: 100% !important; height: auto !important;" alt="Stealthy architecture flowchart" />
61+
🎭 Stealthy Playwright examples are located in [./examples/cdp_mode/playwright/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/).
6862

69-
(For maximum stealth, use <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md">CDP Mode</a>, which includes <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md">Stealthy Playwright Mode</a>)
63+
📚 Examples that have `test_` or `_test` in the filename are specifically designed to run with `pytest` / `pynose`. Other examples run directly with raw `python` (those files generally start with `raw_` to avoid confusion).
7064

7165
--------
7266

@@ -76,18 +70,22 @@
7670
from seleniumbase import sb_cdp
7771

7872
sb = sb_cdp.Chrome(incognito=True)
79-
sb.goto("www.planetminecraft.com/account/sign_in")
80-
sb.solve_captcha()
81-
# "LOG IN" is enabled when the CAPTCHA is bypassed
82-
sb.wait_for_element_absent("input[disabled]")
83-
sb.sleep(2)
73+
sb.goto("https://www.planetminecraft.com/account")
74+
sb.assert_element('input[name="login"]')
75+
sb.type('input[name="email"]', "test@example.com")
76+
sb.type('input[name="password"]', "Fake_Password")
77+
sb.click("input#autologin") # The checkbox
78+
if sb.is_element_visible("input[disabled]"):
79+
sb.solve_captcha() # Enables the input
80+
sb.assert_element_absent("input[disabled]")
81+
sb.sleep(1.5)
8482
sb.quit()
8583
```
8684

8785
> `python raw_cdp_planetmc.py`
8886
8987
<p align="left">
90-
<img src="https://seleniumbase.github.io/other/pmc_captcha_2.png" width="570" style="max-width: 100% !important; height: auto !important;" alt="Cloudflare Turnstile bypassed successfully" />
88+
<img src="https://seleniumbase.github.io/other/pmc_captcha_2.png" width="530" style="max-width: 100% !important; height: auto !important;" alt="Cloudflare Turnstile bypassed successfully" />
9189
</p>
9290

9391
✅ <b><code>sb.solve_captcha()</code></b> handles CAPTCHAs that aren't bypassed automatically.<br />(If called when there's no CAPTCHA on the page, then nothing happens / no-op.)
@@ -99,51 +97,22 @@ sb.quit()
9997
```python
10098
from seleniumbase import sb_cdp
10199

102-
sb = sb_cdp.Chrome()
100+
sb = sb_cdp.Chrome(fast=True)
103101
sb.goto("https://news.ycombinator.com/submitted?id=seleniumbase")
104102
elements = sb.find_elements("span.titleline > a")
105103
for element in elements:
106-
print("* %s" % element.text)
104+
print("* " + element.text)
107105
```
108106

109107
> `python raw_cdp_yc_news.py`
110108
111109
<p align="left">
112-
<img src="https://seleniumbase.github.io/other/yc_news_results.png" alt="SeleniumBase" width="524" style="max-width: 100% !important; height: auto !important;"/>
110+
<img src="https://seleniumbase.github.io/other/yc_news_results.png" alt="SeleniumBase" width="510" style="max-width: 100% !important; height: auto !important;"/>
113111
</p>
114112

115-
----
116-
117-
<p align="left">📝 Here’s <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_cdp_methods.py" target="_blank">SeleniumBase/examples/cdp_mode/raw_cdp_methods.py</a>:<br />(It performs several different actions on the web page)</p>
118-
119-
```python
120-
from seleniumbase import sb_cdp
121-
122-
sb = sb_cdp.Chrome(fast=True)
123-
sb.goto("https://seleniumbase.io/demo_page")
124-
sb.type("input", "Quickly type text!")
125-
sb.press_keys("textarea", "Slowly type text!")
126-
sb.click("#myButton")
127-
sb.set_value("input#mySlider", "100")
128-
sb.click_visible_elements("input.checkBoxClassB")
129-
sb.select_option_by_text("#mySelect", "Set to 75%")
130-
sb.hover_and_click("#myDropdown", "#dropOption2")
131-
sb.click("#checkBox1")
132-
sb.drag_and_drop("img#logo", "div#drop2")
133-
sb.nested_click("iframe#myFrame3", ".fBox")
134-
sb.highlight("#myButton")
135-
sb.quit()
136-
```
137-
138-
> `python raw_cdp_methods.py`
139-
140-
<img src="https://seleniumbase.github.io/cdn/gif/demo_page_6.gif" width="580" style="max-width: 100% !important; height: auto !important;" alt="SeleniumBase Example" />
141-
142-
ℹ️ Setting `fast=True` lets your automation go at full speed, which may be useful if maximum stealth isn't your goal.
143-
144-
----
113+
--------
145114

146-
<p align="left"><b>📝 <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py" target="_blank">This example</a> bypasses Cloudflare's challenge page with UC + CDP Mode:</b><br />(If the Turnstile isn't bypassed automatically, <b><code>sb.solve_captcha()</code></b> handles it.)</p>
115+
<p align="left"><b>📝 <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_gitlab.py" target="_blank">This example</a> bypasses Cloudflare's challenge page with UC + CDP Mode:</b></p>
147116

148117
```python
149118
from seleniumbase import SB
@@ -160,22 +129,14 @@ with SB(uc=True, test=True, locale="en") as sb:
160129
> `python raw_gitlab.py`
161130
162131
<p align="left">
163-
<img src="https://seleniumbase.github.io/other/gitlab_bypass_2.png" alt="SeleniumBase" width="430" style="max-width: 100% !important; height: auto !important;"/>
132+
<img src="https://seleniumbase.github.io/other/gitlab_bypass_2.png" alt="SeleniumBase" width="420" style="max-width: 100% !important; height: auto !important;"/>
164133
</p>
165134

166135
--------
167136

168-
🧪 End-to-End Testing examples are located in [./examples/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples).
169-
170-
🐙 Stealthy CDP Mode examples are located in [./examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
171-
172-
🎭 Stealthy Playwright examples are located in [./examples/cdp_mode/playwright/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/).
173-
174-
--------
175-
176137
<h3 align="left">🌐 CLI Options for Supported Chromium Browsers</h3>
177138

178-
<p>💡 You can set the Chromium browser to use via command line parameters:</p>
139+
<p>💡 You can set which Chromium browser to use via command-line parameters:</p>
179140

180141
```zsh
181142
python SCRIPT.py --chromium # Use the unbranded Chromium browser
@@ -194,11 +155,13 @@ sb = sb_cdp.Chrome(use_chromium=True)
194155

195156
--------
196157

197-
<h3>🧪 Comprehensive E2E Testing with <code>pytest</code>:</h3>
158+
<h3 align="left">⚙️ Stealthy architecture flowchart:</h3>
198159

199-
📚 The [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder includes over 150 ready-to-run examples of E2E testing. Examples that start with `test_` or end with `_test.py`/`_tests.py` run with `pytest`. Other examples run directly with raw `python` (those generally start with `raw_` to avoid confusion).
160+
<img src="https://seleniumbase.github.io/other/sb_architecture.png" width="540" style="max-width: 100% !important; height: auto !important;" alt="Stealthy architecture flowchart" />
200161

162+
--------
201163

164+
<h3>🧪 Comprehensive E2E Testing with <code>pytest</code>:</h3>
202165

203166
<p align="left"><b>📝 <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_get_swag.py" target="_blank">This example</a> tests an e-commerce site with <code>pytest</code>:</b></p>
204167

@@ -228,6 +191,8 @@ class MyTestClass(BaseCase):
228191
229192
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_get_swag.py"><img src="https://seleniumbase.github.io/cdn/gif/fast_swag_2.gif" alt="SeleniumBase Test" width="500" style="max-width: 100% !important; height: auto !important;" /></a>
230193

194+
🥷 For stealth with `pytest`, add `--uc` as a command-line option.
195+
231196
--------
232197

233198
<p align="left"><b>📝 <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_coffee_cart.py" target="_blank">This example</a> tests another e-commerce site with <code>pytest</code>:</b></p>
@@ -254,7 +219,7 @@ pytest test_demo_site.py
254219

255220
> Easy to type, click, select, toggle, drag & drop, and more.
256221
257-
(For more examples, see the <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">SeleniumBase/examples/</a> folder.)
222+
📚 For more examples, see the <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">SeleniumBase/examples/</a> folder.
258223

259224
--------
260225

‎examples/cdp_mode/playwright/raw_clearcote_sync.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626
score = sb.get_text("div.text-successText")
2727
print(f" ❌ Fingerprint tampering detected! Score: {score}")
2828
sb.sleep(1)
29+
folder = "downloaded_files"
30+
file_name = "c_audit_results_pw.pdf"
31+
sb.save_as_pdf(file_name, folder)
32+
print('"./%s/%s" was saved!' % (folder, file_name))

‎examples/cdp_mode/playwright/raw_footlocker_sync.py‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33

44
sb = sb_cdp.Chrome(locale="en", ad_block=True)
55
sb.goto("https://www.footlocker.com/")
6+
sb.click_if_visible('button[id*="Agree"]', timeout=3)
7+
sb.click('input[name="query"]')
8+
search = "Nike Shoes"
9+
sb.press_keys('input[name="query"]', search)
610
endpoint_url = sb.get_endpoint_url()
711

812
with sync_playwright() as p:
913
browser = p.chromium.connect_over_cdp(endpoint_url)
1014
page = browser.contexts[0].pages[0]
1115
input_field = 'input[name="query"]'
12-
page.wait_for_selector(input_field)
13-
sb.sleep(1.5)
14-
sb.click_if_visible('button[id*="Agree"]')
15-
sb.sleep(0.6)
16-
page.click(input_field)
17-
sb.sleep(0.6)
18-
search = "Nike Shoes"
19-
page.type(input_field, search)
2016
sb.sleep(1.2)
2117
page.click('ul[id*="typeahead"] li div')
2218
sb.sleep(3.5)
23-
elements = sb.select_all("a[data-productcard]")
24-
if elements:
19+
items = page.locator("a[data-productcard]")
20+
count = items.count()
21+
if count:
2522
print('**** Found results for "%s": ****' % search)
2623
else:
2724
print('**** No results found for "%s". ****' % search)
28-
for element in elements:
25+
for i in range(items.count()):
2926
print("------------------ >>>")
30-
print("* " + element.text)
31-
sb.sleep(2)
27+
print("* " + items.nth(i).inner_text().replace("\n", " "))
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
from playwright.sync_api import expect
12
from playwright.sync_api import sync_playwright
23
from seleniumbase import sb_cdp
34

4-
sb = sb_cdp.Chrome()
5+
sb = sb_cdp.Chrome(incognito=True)
56
endpoint_url = sb.get_endpoint_url()
67

78
with sync_playwright() as p:
89
browser = p.chromium.connect_over_cdp(endpoint_url)
910
page = browser.contexts[0].pages[0]
10-
page.goto("https://www.planetminecraft.com/account/sign_in/")
11-
sb.solve_captcha()
12-
input_disabled = page.locator("input[disabled]")
13-
input_disabled.wait_for(state="hidden", timeout=5000)
14-
page.wait_for_timeout(2000)
11+
page.goto("https://www.planetminecraft.com/account")
12+
expect(page.locator('input[name="login"]')).to_be_visible()
13+
14+
email_field = page.locator('input[name="email"]')
15+
email_field.press_sequentially("test@example.com", delay=55)
16+
page.locator('input[name="password"]').fill("Fake_Password")
17+
page.locator("input#autologin").click(force=True)
18+
19+
if page.locator('input[disabled]').is_visible():
20+
sb.solve_captcha() # Enables the input button
21+
expect(page.locator("input[disabled]")).to_be_hidden()
22+
page.wait_for_timeout(1500)

‎examples/cdp_mode/playwright/raw_yc_news_sync.py‎

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

4-
sb = sb_cdp.Chrome()
4+
sb = sb_cdp.Chrome(fast=True)
55
endpoint_url = sb.get_endpoint_url()
66

77
with sync_playwright() as p:
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from seleniumbase import sb_cdp
22

33
sb = sb_cdp.Chrome(incognito=True)
4-
sb.goto("www.planetminecraft.com/account/sign_in")
5-
sb.solve_captcha()
6-
# "LOG IN" is enabled when the CAPTCHA is bypassed
7-
sb.wait_for_element_absent("input[disabled]")
8-
sb.sleep(2)
4+
sb.goto("https://www.planetminecraft.com/account")
5+
sb.assert_element('input[name="login"]')
6+
sb.type('input[name="email"]', "test@example.com")
7+
sb.type('input[name="password"]', "Fake_Password")
8+
sb.click("input#autologin") # The checkbox
9+
if sb.is_element_visible("input[disabled]"):
10+
sb.solve_captcha() # Enables the input button
11+
sb.assert_element_absent("input[disabled]")
12+
sb.sleep(1.5)
913
sb.quit()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from seleniumbase import sb_cdp
22

3-
sb = sb_cdp.Chrome()
3+
sb = sb_cdp.Chrome(fast=True)
44
sb.goto("https://news.ycombinator.com/submitted?id=seleniumbase")
55
elements = sb.find_elements("span.titleline > a")
66
for element in elements:
7-
print("* %s" % element.text)
7+
print("* " + element.text)

‎examples/cdp_mode/raw_footlocker.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
44
sb.activate_cdp_mode()
55
sb.goto("https://www.footlocker.com/")
6-
sb.sleep(2.5)
7-
sb.click_if_visible('button[id*="Agree"]')
8-
sb.sleep(0.6)
6+
sb.click_if_visible('button[id*="Agree"]', timeout=3)
97
sb.click('input[name="query"]')
10-
sb.sleep(0.6)
118
search = "Nike Shoes"
129
sb.press_keys('input[name="query"]', search)
13-
sb.sleep(2.5)
10+
sb.sleep(1.2)
1411
sb.click('ul[id*="typeahead"] li div')
1512
sb.sleep(3.5)
1613
elements = sb.select_all("a[data-productcard]")
@@ -21,4 +18,3 @@
2118
for element in elements:
2219
print("------------------ >>>")
2320
print("* " + element.text)
24-
sb.sleep(2)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True) as sb:
3+
with SB(uc=True, fast=True) as sb:
44
sb.activate_cdp_mode()
55
sb.goto("https://news.ycombinator.com/submitted?id=seleniumbase")
66
elements = sb.find_elements("span.titleline > a")
77
for element in elements:
8-
print("* %s" % element.text)
8+
print("* " + element.text)

‎examples/cdp_mode/raw_planetmc.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, guest=True) as sb:
3+
with SB(uc=True, test=True, incognito=True) as sb:
44
sb.activate_cdp_mode()
5-
sb.goto("www.planetminecraft.com/account/sign_in")
6-
sb.solve_captcha()
7-
# "LOG IN" is enabled when the CAPTCHA is bypassed
8-
sb.wait_for_element_absent("input[disabled]")
9-
sb.sleep(2)
5+
sb.goto("https://www.planetminecraft.com/account")
6+
sb.assert_element('input[name="login"]')
7+
sb.assert_text("Sign in to Planet Minecraft")
8+
sb.type('input[name="email"]', "test@example.com")
9+
sb.type('input[name="password"]', "Fake_Password")
10+
sb.click("input#autologin") # The checkbox
11+
if sb.is_element_visible("input[disabled]"):
12+
sb.solve_captcha() # Enables the input button
13+
sb.assert_element_absent("input[disabled]")
14+
sb.sleep(1.5)

0 commit comments

Comments
 (0)