Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<meta property="og:image" content="https://seleniumbase.github.io/cdn/img/mac_sb_logo_5b.png" />
<link rel="icon" href="https://seleniumbase.github.io/img/logo7.png" />

<h3 align="center" class="hero__title"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/nice_logo_8t.png" alt="SeleniumBase" title="SeleniumBase" width="420" /></a><br /><b>All-in-one Browser Automation Framework:<br />Web Crawling / Testing / Scraping / Stealth</b></h3>
<h3 align="center" class="hero__title"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/nice_logo_8t.png" alt="SeleniumBase" title="SeleniumBase" width="450" /></a><br /><b>A Complete Browser Automation Experience:<br />Web Crawling / Testing / Scraping / Stealth</b></h3>

<p align="center">
<a href="https://pypi.python.org/pypi/seleniumbase" target="_blank" rel="noopener"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?style=flat-square&color=3399EE" alt="PyPI version" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank" rel="noopener"><img src="https://flat.badgen.net/github/checks/seleniumbase/SeleniumBase/master?label=CI&" alt="CI Status" height="20" /></a> <a href="https://seleniumbase.io" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg?style=flat-square" alt="SeleniumBase Docs" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/license-MIT-33A6C6.svg?style=flat-square" title="SeleniumBase" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/mcp_servers" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/MCP-tool_info-7C6EE5?style=flat-square" height="20" /></a> <a href="https://pepy.tech/projects/seleniumbase?timeRange=threeMonths&category=version&includeCIDownloads=true&granularity=daily&viewType=line&versions=*" target="_blank" rel="noopener"><img src="https://static.pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" height="20" /></a><br />
<a href="https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/docs-📺-D844E8.svg?style=flat-square&logo=YouTube&logoColor=white&label=YouTube" alt="YouTube Channel" height="20" /></a> <a href="https://www.facebook.com/SeleniumBase/" target="_blank" rel="noopener"> <img src="https://img.shields.io/badge/Facebook-4K_followers-1877F2?style=flat-square&logo=facebook&logoColor=white" alt="SeleniumBase Facebook Followers" height="20" /></a> <a href="https://x.com/seleniumbase" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/-1K_followers-1DA1F2?style=flat-square&logo=x&logoColor=white&labelColor=555555" alt="SeleniumBase X Followers" height="20" /></a> <a href="https://discord.gg/EdhQTn3EyE" target="_blank" rel="noopener"><img src="https://flat.badgen.net/discord/online-members/EdhQTn3EyE?color=7289DA&icon=discord&label=Discord" height="20" alt="Discord Status" /></a> <a href="https://github.com/seleniumbase/SeleniumBase" target="_blank" rel="noopener"><img src="https://badgen.net/github/stars/seleniumbase/SeleniumBase" title="Stars" height="20" /></a>
<a href="https://pypi.python.org/pypi/seleniumbase" target="_blank" rel="noopener"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?style=flat-square&color=3399EE" alt="PyPI version" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank" rel="noopener"><img src="https://flat.badgen.net/github/checks/seleniumbase/SeleniumBase/master?label=CI&" alt="CI Status" height="20" /></a> <a href="https://seleniumbase.io" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg?style=flat-square" alt="SeleniumBase Docs" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/license-MIT-33A6C6.svg?style=flat-square" title="SeleniumBase" height="20" /></a><br /><a href="https://github.com/seleniumbase/SeleniumBase/tree/master/mcp_servers" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/MCP-tool_info-7C6EE5?style=flat-square" height="20" /></a> <a href="https://pepy.tech/projects/seleniumbase?timeRange=threeMonths&category=version&includeCIDownloads=true&granularity=daily&viewType=line&versions=*" target="_blank" rel="noopener"><img src="https://static.pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" height="20" /></a> <a href="https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/docs-📺-D844E8.svg?style=flat-square&logo=YouTube&logoColor=white&label=YouTube" alt="YouTube Channel" height="20" /></a> <a href="https://github.com/seleniumbase/SeleniumBase" target="_blank" rel="noopener"><img src="https://badgen.net/github/stars/seleniumbase/SeleniumBase" title="Stars" height="20" /></a>
</p>

<p align="center">
Expand Down Expand Up @@ -50,20 +49,26 @@
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/case_plans.md">🗂️ CPlans</a>
</p>

<h4>SeleniumBase is the professional toolkit for web automation activities. Built for testing websites, bypassing CAPTCHAs, enhancing productivity, completing tasks, and scaling your business.</h4>

--------

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

<p align="left"><a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples" target="_blank" rel="noopener"><img src="https://seleniumbase.github.io/cdn/gif/google_search.gif" alt="SeleniumBase Google Search" title="SeleniumBase Google Search" width="480" /></a></p>

--------

<h3 align="left">⚙️ High-level architecture and special modes:</h3>
<h3 align="left"><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> SeleniumBase Chromium architecture and modes:</h3>

<img src="https://seleniumbase.github.io/other/sb_architecture.png" width="600" style="max-width: 100% !important; height: auto !important;" alt="Stealthy architecture flowchart" />

<img src="https://seleniumbase.github.io/other/sb_architecture.png" width="595" style="max-width: 100% !important; height: auto !important;" alt="Stealthy architecture flowchart" />
> (*Note that "Regular Mode" also supports Safari/WebKit and Firefox/Gecko.*)

<ul>
<li>🐙 <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><b>CDP Mode</b></a> <b>bypasses bot-detection with Chromium-based browsers.</b></li>
<li>🎭 <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> <b>extends CDP Mode's stealth to Playwright.</b></li>
</ul>
<ul>
<li><code><b>pip install seleniumbase</b></code> for the main framework.</li>
<li><code><b>pip install playwright</b></code> for the optional integration.</li>
</ul>

--------

Expand All @@ -84,21 +89,21 @@
```python
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome() # Launches a stealth browser
sb = sb_cdp.Chrome() # Launch a stealth browser
sb.goto("https://www.planetminecraft.com/account")
sb.type('[name="email"]', "Test123")
sb.type('[name="password"]', "Pass")
sb.click("input#autologin") # Unchecks a checkbox
sb.solve_captcha() # (as backup if not automatic)
sb.click("input#autologin") # Uncheck a checkbox
sb.solve_captcha() # (fallback if not automatic)
sb.assert_element('input[name="login"]')
sb.assert_element_not_visible("input[disabled]")
sb.sleep(1) # (only to slow down the live demo)
sb.quit() # (otherwise quits automatically at end)
sb.sleep(1) # (see the live demo more easily)
sb.quit()
```

<p align="left">
<img src="https://seleniumbase.github.io/other/pmc_captcha_3.png" width="542" style="max-width: 100% !important; height: auto !important;" alt="Cloudflare Turnstile bypassed successfully" />
<br /><em>(Note that the click action only unchecked the "Stay signed in" checkbox.)</em>
<img src="https://seleniumbase.github.io/other/pmc_captcha_3.png" width="572" style="max-width: 100% !important; height: auto !important;" alt="Cloudflare Turnstile bypassed successfully" />
<br /><em>(Note: In this example, the click only unchecks the "Stay signed in" checkbox.)</em>
</p>

--------
Expand Down Expand Up @@ -820,6 +825,7 @@ pytest test_coffee_cart.py --trace
--rs | --reuse-session # (Reuse browser session for all tests.)
--rcs | --reuse-class-session # (Reuse session for tests in class.)
--crumbs # (Delete all cookies between tests reusing a session.)
--no-tt # (Skips "--test-type" when using Proxy Mode. Adds stealth.)
--disable-beforeunload # (Disable the "beforeunload" event on Chrome.)
--window-position=X,Y # (Set the browser's starting window position.)
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)
Expand Down
2 changes: 1 addition & 1 deletion examples/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h2><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32"></a> Example Tests:</h2>

<h4>(For stealthy examples, see <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode">./cdp_mode/</a> and <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/">./cdp_mode/playwright/</a>)</h4>
<h3>(For stealthy examples, see <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode">./cdp_mode/</a> and <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/">./cdp_mode/playwright/</a>)</h3>

<p align="left"><a align="center" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py"><img align="center" src="https://seleniumbase.github.io/cdn/img/sb_demo_page.png" alt="SeleniumBase Demo Page" width="420" /></a></p>

Expand Down
4 changes: 2 additions & 2 deletions examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .google_objects import HomePage, ResultsPage
except Exception:
from google_objects import HomePage, ResultsPage
BaseCase.main(__name__, __file__, "--uc")
BaseCase.main(__name__, __file__, "--uc", "--chromium")


class GoogleTests(BaseCase):
Expand All @@ -14,7 +14,7 @@ def test_google_dot_com(self):
print("\n Skipping test in headless mode.")
self.skip("Skipping test in headless mode.")
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.get_new_driver(undetectable=True, use_chromium=True)
self.goto("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.assert_title_contains("Google")
Expand Down
7 changes: 4 additions & 3 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
sb.activate_cdp_mode()
sb.goto("https://www.pokemon.com/us/pokedex")
sb.sleep(1.5)
sb.click_if_visible("button#onetrust-accept-btn-handler")
sb.click_if_visible("#onetrust-accept-btn-handler", timeout=2)
sb.sleep(1.5)
sb.click('b:contains("Show Advanced Search")')
sb.sleep(2.5)
sb.click('span[data-type="type"][data-value="electric"]')
sb.sleep(0.7)
sb.sleep(1)
sb.scroll_into_view("a#advSearch")
sb.sleep(0.7)
sb.sleep(1)
sb.click("a#advSearch")
sb.sleep(1.2)
sb.click('img[src*="img/pokedex/detail/025.png"]')
Expand Down Expand Up @@ -467,6 +467,7 @@ sb.select_option_by_index(dropdown_selector, option)
sb.select_option_by_value(dropdown_selector, option)
sb.flash(selector, duration=1, color="44CC88", pause=0)
sb.highlight(selector, scroll=True, timeout=None)
sb.highlight_if_visible(selector, scroll=True, timeout=0)
sb.focus(selector, timeout=None)
sb.highlight_overlay(selector)
sb.get_parent(element)
Expand Down
4 changes: 1 addition & 3 deletions examples/cdp_mode/playwright/raw_clearcote_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
page = browser.contexts[0].pages[0]
page.goto("https://www.clearcotelabs.com/audit")
sb.click('button[aria-label="Marker 1"]')
sb.click('button[aria-label="Marker 2"]')
sb.click('button[aria-label="Marker 3"]')
sb.press_keys("input", "audit")
sb.press_keys("input", "Audit")
sb.set_value('input[type="range"]', "100")
sb.click_and_hold("button[data-interaction-hold]")
sb.select_option_by_text("select", "Mouse")
Expand Down
8 changes: 6 additions & 2 deletions examples/cdp_mode/raw_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ async def main():
sb = sb_cdp.Chrome("https://www.priceline.com/")
sb.sleep(2.5)
sb.internalize_links() # Don't open links in a new tab
sb.click("#link_header_nav_experiences")
sb.click_if_visible('[aria-label="Close Modal"]')
sb.sleep(0.2)
sb.click('a[href*="experiences.priceline"]')
sb.sleep(3.5)
sb.remove_elements("msm-cookie-banner")
sb.sleep(1.5)
Expand All @@ -70,5 +72,7 @@ async def main():
print("************")
cards = sb.select_all('span[data-automation*="product-list-card"]')
for card in cards:
print("* %s" % card.text)
card_text = card.text.strip()
if len(card_text) >= 20:
print("* %s" % card_text)
sb.quit()
6 changes: 4 additions & 2 deletions examples/cdp_mode/raw_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
sb.goto("https://www.priceline.com/")
sb.sleep(2)
sb.internalize_links() # Don't open links in a new tab
sb.click("#link_header_nav_experiences")
sb.click('a[href*="experiences.priceline"]')
sb.sleep(3)
sb.remove_elements("msm-cookie-banner")
sb.sleep(1)
Expand All @@ -31,7 +31,9 @@ def main():
sb.sleep(0.2)
cards = sb.select_all('span[data-automation*="product-list-card"]')
for card in cards:
print("* %s" % card.text)
card_text = card.text.strip()
if len(card_text) >= 20:
print("* %s" % card_text)
sb.quit()


Expand Down
4 changes: 1 addition & 3 deletions examples/cdp_mode/raw_cdp_clearcote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
sb = sb_cdp.Chrome()
sb.goto("https://www.clearcotelabs.com/audit")
sb.click('button[aria-label="Marker 1"]')
sb.click('button[aria-label="Marker 2"]')
sb.click('button[aria-label="Marker 3"]')
sb.press_keys("input", "audit")
sb.press_keys("input", "Audit")
sb.set_value('input[type="range"]', "100")
sb.click_and_hold("button[data-interaction-hold]")
sb.select_option_by_text("select", "Mouse")
Expand Down
11 changes: 7 additions & 4 deletions examples/cdp_mode/raw_cdp_google.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
sb = sb_cdp.Chrome(use_chromium=True)
sb.goto("https://google.com/ncr")
sb.click_if_visible('button:contains("Accept all")')
sb.type('[name="q"]', "SeleniumBase site:github.com")
sb.sleep(0.2)
sb.click('[value="Google Search"]')
sb.press_keys('[name="q"]', "SeleniumBase GitHub Page")
sb.sleep(0.5)
if sb.is_element_visible('[value="Google Search"]'):
sb.click('[value="Google Search"]')
else:
sb.press_keys('[name="q"]', "\n")
sb.sleep(1)
sb.click_if_visible('h3:contains("seleniumbase/SeleniumBase")')
sb.sleep(1)
Expand Down
14 changes: 6 additions & 8 deletions examples/cdp_mode/raw_cdp_mode.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Bypass bot-detection with SeleniumBase CDP Mode.
Assert statements that aren't met raise exceptions.
"""
"""Bypass bot-detection with SeleniumBase CDP Mode."""
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome() # Launches a stealth browser
sb = sb_cdp.Chrome() # Launch a stealth browser
sb.goto("https://www.planetminecraft.com/account")
sb.type('[name="email"]', "Test123")
sb.type('[name="password"]', "Pass")
sb.click("input#autologin") # Unchecks a checkbox
sb.solve_captcha() # (as backup if not automatic)
sb.click("input#autologin") # Uncheck a checkbox
sb.solve_captcha() # (fallback if not automatic)
sb.assert_element('input[name="login"]')
sb.assert_element_not_visible("input[disabled]")
sb.sleep(1) # (only to slow down the live demo)
sb.quit() # (otherwise quits automatically at end)
sb.sleep(1) # (see the live demo more easily)
sb.quit()
17 changes: 17 additions & 0 deletions examples/cdp_mode/raw_cdp_rastreator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
sb.goto("https://www.rastreator.com/seguros-de-coche")
sb.hover_element("body")
sb.click_if_visible(".accept-btn", timeout=2)
sb.click('button[type="submit"]')
sb.sleep(1)
sb.click("label:has(#radioThinkingToBuying)")
sb.sleep(1)
sb.click("label:has(#radioNewCar)")
sb.sleep(1)
sb.solve_captcha()
sb.sleep(1)
expected_text = "El coche que quieres asegurar"
sb.highlight(f'h2:contains("{expected_text}")')
sb.sleep(2)
6 changes: 4 additions & 2 deletions examples/cdp_mode/raw_cdp_with_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sb.internalize_links() # Don't open links in a new tab
sb.click_if_visible('[aria-label="Close Modal"]')
sb.sleep(0.2)
sb.click("#link_header_nav_experiences")
sb.click('a[href*="experiences.priceline"]')
sb.sleep(3.5)
sb.remove_elements("msm-cookie-banner")
sb.sleep(1.5)
Expand All @@ -29,4 +29,6 @@
sb.sleep(0.2)
cards = sb.select_all('span[data-automation*="product-list-card"]')
for card in cards:
print("* %s" % card.text)
card_text = card.text.strip()
if len(card_text) >= 20:
print("* %s" % card_text)
25 changes: 25 additions & 0 deletions examples/cdp_mode/raw_clearcote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
sb.activate_cdp_mode()
sb.goto("https://www.clearcotelabs.com/audit")
sb.click('button[aria-label="Marker 1"]')
sb.press_keys("input", "Audit")
sb.set_value('input[type="range"]', "100")
sb.click_and_hold("button[data-interaction-hold]")
sb.select_option_by_text("select", "Mouse")
sb.click('button:contains("Run the audit")')
sb.sleep(6)
sb.assert_element("div.text-successText", timeout=10)
try:
sb.assert_text("100", "div.text-successText", timeout=5)
sb.highlight("div.text-successText")
print(" ✅ The browser fingerprint is clean! Score: 100")
except Exception:
score = sb.get_text("div.text-successText")
print(f" ❌ Fingerprint tampering detected! Score: {score}")
sb.sleep(1)
folder = "downloaded_files"
file_name = "c_audit_results.pdf"
sb.save_as_pdf(file_name, folder)
print('"./%s/%s" was saved!' % (folder, file_name))
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sb.activate_cdp_mode()
sb.goto("https://www.pokemon.com/us/pokedex")
sb.sleep(1.5)
sb.click_if_visible("button#onetrust-accept-btn-handler")
sb.click_if_visible("#onetrust-accept-btn-handler", timeout=2)
sb.sleep(1.5)
sb.click('b:contains("Show Advanced Search")')
sb.sleep(2.5)
sb.click('span[data-type="type"][data-value="electric"]')
sb.sleep(0.7)
sb.sleep(1)
sb.scroll_into_view("a#advSearch")
sb.sleep(0.7)
sb.sleep(1)
sb.click("a#advSearch")
sb.sleep(1.2)
sb.click('img[src*="img/pokedex/detail/025.png"]')
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_reddit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Reddit Search / Bypasses reCAPTCHA."""
from seleniumbase import SB

with SB(uc=True, test=True, use_chromium=True) as sb:
with SB(uc=True, test=True, use_chromium=True, guest=True) as sb:
search = "Reddit Scraping"
sb.activate_cdp_mode()
sb.goto("https://www.reddit.com/r/webscraping/")
Expand Down
Loading
Loading