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
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ pip install -e .
<summary> ▶️ Here's sample output from a chromedriver download. (<b>click to expand</b>)</summary>

```zsh
*** chromedriver to download = 148.0.7778.178 (Latest Stable)
*** chromedriver to download = 149.0.7827.54 (Latest Stable)

Downloading chromedriver-mac-arm64.zip from:
https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.178/mac-arm64/chromedriver-mac-arm64.zip ...
https://storage.googleapis.com/chrome-for-testing-public/149.0.7827.54/mac-arm64/chromedriver-mac-arm64.zip ...
Download Complete!

Extracting ['chromedriver'] from chromedriver-mac-arm64.zip ...
Expand All @@ -520,8 +520,8 @@ The file [chromedriver] was saved to:
~/github/SeleniumBase/seleniumbase/drivers/
chromedriver

Making [chromedriver 148.0.7778.178] executable ...
[chromedriver 148.0.7778.178] is now ready for use!
Making [chromedriver 149.0.7827.54] executable ...
[chromedriver 149.0.7827.54] is now ready for use!
```

</details>
Expand Down Expand Up @@ -853,7 +853,6 @@ pytest test_coffee_cart.py --trace
--screenshot # (Save a screenshot at the end of each test.)
--no-screenshot # (No screenshots saved unless tests directly ask it.)
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
--wire # (Use selenium-wire's webdriver for replacing selenium webdriver.)
--external-pdf # (Set Chromium "plugins.always_open_pdf_externally":True.)
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
--list-fail-page # (After each failing test, list the URL of the failure.)
Expand Down
11 changes: 5 additions & 6 deletions examples/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

<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>

* <b>SeleniumBase</b> "tests" are run with <b>pytest</b>.
* Many <b>SeleniumBase</b> "tests" run with <b><code>pytest</code></b>.
* Chrome is the default browser if not specified.
* Tests are structured using [25 unique syntax formats](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
* Tests are structured using [25 unique design patterns](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
* Logs from test failures are saved to `./latest_logs/`.
* Tests can be run with [multiple command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md).
* Examples can be found in [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples).
* For stealthy examples, see [SeleniumBase/examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
* Stealthy CDP Mode examples: [SeleniumBase/examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
* Stealthy Playwright examples: [./examples/cdp_mode/playwright/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md).

(NOTE: Some example tests fail on purpose to demonstrate [logging features](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).)

--------

<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Example tests with run commands to help you get started:</h3>

--------
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Example tests with run commands:</h3>

Run an [example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py): (Default option: `--chrome`)

Expand Down
7 changes: 3 additions & 4 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ with SB(uc=True, test=True, ad_block=True) as sb:
price_text = price_text.split("current price ")[-1]
price_text = price_text.split(" ")[0]
print(" (" + price_text + ")")
item.scroll_into_view()
```

</details>
Expand Down Expand Up @@ -662,8 +663,7 @@ await tab.set_window_size(left=0, top=0, width=1280, height=1024)
await tab.set_window_rect(left=0, top=0, width=1280, height=1024)
await tab.activate()
await tab.bring_to_front()
await tab.set_window_state(
left=0, top=0, width=1280, height=720, state="normal")
await tab.set_window_state(left=0, top=0, width=1280, height=720, state="normal")
await tab.get_navigation_history()
await tab.get_user_agent()
await tab.get_cookie_string()
Expand All @@ -677,8 +677,7 @@ await tab.wait_for(selector="", text="", timeout=10)
await tab.set_attributes(selector, attribute, value)
await tab.internalize_links()
await tab.download_file(url, filename=None)
await tab.save_screenshot(
filename="auto", format="png", full_page=False)
await tab.save_screenshot(filename="auto", format="png", full_page=False)
await tab.print_to_pdf(filename="auto")
await tab.set_download_path(path)
await tab.get_all_linked_sources()
Expand Down
4 changes: 3 additions & 1 deletion examples/cdp_mode/raw_ad_blocking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Test Ad-Blocking using mycdp.network.set_blocked_urls().
tab.send() is the stealthy version of execute_cdp_cmd()."""
import mycdp
from seleniumbase import decorators
from seleniumbase import sb_cdp
Expand Down Expand Up @@ -28,4 +30,4 @@ async def block_urls(tab):
sb.assert_false("doubleclick.net" in source)
sb.assert_false("google-analytics.com" in source)
sb.post_message("Blocking was successful!")
sb.driver.quit()
sb.quit()
7 changes: 4 additions & 3 deletions examples/cdp_mode/raw_antibot.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""CDP Mode bypasses bot-detection and performs stealthy actions.
sb.press_keys() is a slower sb.type() for human-like speed."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/antibot/login"
sb.activate_cdp_mode(url)
sb.press_keys("input#username", "demo_user")
sb.press_keys("input#password", "secret_pass")
sb.type("input#password", "secret_pass")
sb.click("button#myButton")
sb.sleep(1.5)
sb.sleep(1.4)
sb.click("a#log-in")
sb.assert_text("Welcome!", "h1")
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
sb.sleep(1.5)
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_basic_cdp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from seleniumbase import sb_cdp

url = "https://seleniumbase.io/simple/login"
sb = sb_cdp.Chrome(url)
sb = sb_cdp.Chrome()
sb.open("https://seleniumbase.io/simple/login")
sb.type("#username", "demo_user")
sb.type("#password", "secret_pass")
sb.click('a:contains("Sign in")')
Expand All @@ -14,4 +14,4 @@
print(nav_item.text)
sb.click_link("Sign out")
sb.assert_text("signed out", "#top_message")
sb.driver.stop()
sb.quit()
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_cdp_pixelscan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome(incognito=True)
sb = sb_cdp.Chrome(guest=True, ad_block=True)
sb.open("https://pixelscan.net/fingerprint-check")
sb.sleep(1)
sb.wait_for_element("pxlscn-dynamic-ad")
Expand All @@ -13,3 +13,4 @@
sb.highlight("span.status-success")
sb.highlight("pxlscn-fingerprint-masking p")
sb.highlight("pxlscn-bot-detection p")
print("Bot Not Detected")
9 changes: 9 additions & 0 deletions examples/cdp_mode/raw_cdp_tavus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
sb.open("platform.tavus.io/auth/sign-in?is_developer=true")
sb.sleep(3)
sb.solve_captcha()
sb.sleep(1)
sb.assert_element('input[type="email"]')
sb.assert_element('button[type="submit"]')
1 change: 1 addition & 0 deletions examples/cdp_mode/raw_cdp_walmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
price_text = price_text.split("current price ")[-1]
price_text = price_text.split(" ")[0]
print(" (" + price_text + ")")
item.scroll_into_view()
sb.driver.stop()
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_cf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Using CDP Mode to bypass CAPTCHAs in different ways."""
"""Using CDP Mode to bypass CAPTCHAs in different ways.
PyAutoGUI is installed automatically if not already."""
from seleniumbase import SB

with SB(uc=True, test=True, guest=True) as sb:
Expand Down
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_mfa_login.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from seleniumbase import sb_cdp

url = "https://seleniumbase.io/realworld/login"
sb = sb_cdp.Chrome(url)
sb = sb_cdp.Chrome()
sb.open("https://seleniumbase.io/realworld/login")
sb.type("#username", "demo_user")
sb.type("#password", "secret_pass")
sb.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG")
sb.assert_text("Welcome!", "h1")
sb.click('a:contains("This Page")')
sb.highlight("h1")
sb.highlight("img#image1")
sb.driver.stop()
sb.quit()
2 changes: 2 additions & 0 deletions examples/cdp_mode/raw_mobile_roblox.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Test mobile emulation via mycdp.emulation.set_device_metrics_override().
tab.send() is a stealthy version of Selenium's execute_cdp_cmd() method."""
import mycdp
from seleniumbase import SB

Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_multi_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main(url):
sb.highlight("button")
sb.click("button")
sb.sleep(2)
sb.driver.quit()
sb.quit()


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_pixelscan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from seleniumbase import SB

with SB(uc=True, test=True, incognito=True, ad_block=True) as sb:
with SB(uc=True, test=True, guest=True, ad_block=True) as sb:
url = "https://pixelscan.net/fingerprint-check"
sb.activate_cdp_mode(url)
sb.sleep(1)
Expand All @@ -14,3 +14,4 @@
sb.cdp.highlight("span.status-success")
sb.cdp.highlight("pxlscn-fingerprint-masking p")
sb.cdp.highlight("pxlscn-bot-detection p")
print("Bot Not Detected")
10 changes: 10 additions & 0 deletions examples/cdp_mode/raw_tavus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
sb.activate_cdp_mode()
sb.open("platform.tavus.io/auth/sign-in?is_developer=true")
sb.sleep(3)
sb.solve_captcha()
sb.sleep(1)
sb.assert_element('input[type="email"]')
sb.assert_element('button[type="submit"]')
1 change: 1 addition & 0 deletions examples/cdp_mode/raw_walmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
price_text = price_text.split("current price ")[-1]
price_text = price_text.split(" ")[0]
print(" (" + price_text + ")")
item.scroll_into_view()
5 changes: 4 additions & 1 deletion examples/cdp_mode/raw_wsform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""CDP Mode for bypassing bot-detection & CAPTCHAs.
Note: sb.uc_gui_click_captcha() requires PyAutoGUI,
which is installed automatically if not already."""
from seleniumbase import SB

with SB(uc=True, test=True, locale="en", incognito=True) as sb:
url = "https://wsform.com/demo/"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.scroll_into_view("div.grid")
sb.uc_gui_click_captcha()
sb.uc_gui_click_captcha() # PyAutoGUI mouse click
sb.sleep(2)
25 changes: 9 additions & 16 deletions examples/presenter/multi_uc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Part of the UC presentation"""
"""Part of the UC presentation. (Upgraded for CDP Mode.)"""
import pytest
from random import randint
from seleniumbase import BaseCase
Expand All @@ -7,18 +7,11 @@

@pytest.mark.parametrize("", [[]] * 3)
def test_multi_threaded(sb):
url = "https://gitlab.com/users/sign_in"
sb.driver.uc_open_with_reconnect(url, 3)
sb.set_window_rect(randint(0, 755), randint(38, 403), 700, 500)
try:
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.post_message("SeleniumBase wasn't detected", duration=4)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.driver.uc_open_with_reconnect(url, 3)
try:
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.post_message("SeleniumBase wasn't detected", duration=4)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.fail('Selenium was detected! Try using: "pytest --uc"')
sb.activate_cdp_mode() # If not UC Mode, then 2nd browser
sb.set_window_rect(randint(4, 680), randint(8, 380), 840, 520)
sb.open("https://gitlab.com/users/sign_in")
sb.sleep(2)
sb.solve_captcha()
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.post_message("SeleniumBase wasn't detected", duration=4)
sb._print("\n Success: SeleniumBase wasn't detected! ")
6 changes: 4 additions & 2 deletions examples/raw_antibot_login.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
"""UC Mode has PyAutoGUI methods for stealthy actions.
PyAutoGUI gets installed automatically if not already.
This old UC Mode code is made obsolete by CDP Mode."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
Expand All @@ -7,7 +9,7 @@
sb.uc_gui_write("\t" + "demo_user")
sb.uc_gui_write("\t" + "secret_pass")
sb.uc_gui_press_keys("\t" + " ") # For Single-char keys
sb.sleep(1.5)
sb.sleep(1.4)
sb.uc_gui_press_keys(["\t", "ENTER"]) # Multi-char keys
sb.reconnect(1.8)
sb.assert_text("Welcome!", "h1")
Expand Down
11 changes: 5 additions & 6 deletions examples/raw_brotector_captcha.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/brotector"
sb.uc_open_with_disconnect(url, 2.2)
sb.uc_gui_press_key("\t")
sb.uc_gui_press_key(" ")
sb.reconnect(2.2)
sb.activate_cdp_mode()
sb.open("https://seleniumbase.io/apps/brotector")
sb.click("button span#mySpan")
sb.assert_text("SUCCESS", "label#pText")
sb.highlight("label#pText")
2 changes: 2 additions & 0 deletions examples/raw_cdp_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""NOTE: This uses plain UC Mode, which was replaced by UC + CDP Mode.
PyAutoGUI is installed automatically for uc_gui methods if not already."""
from rich.pretty import pprint
from seleniumbase import Driver

Expand Down
9 changes: 5 additions & 4 deletions examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""CDP Mode for bypassing bot-detection & CAPTCHAs."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/form_turnstile"
sb.uc_open_with_reconnect(url, 1.1)
sb.activate_cdp_mode()
sb.open("seleniumbase.io/apps/form_turnstile")
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "test@test.test")
sb.press_keys("#phone", "1-555-555-5555")
Expand All @@ -12,8 +13,8 @@
sb.click('span:contains("9:00 PM")')
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.scroll_to('div[class*="cf-turnstile"]')
sb.uc_gui_handle_captcha()
sb.scroll_down(40)
sb.solve_captcha()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
Expand Down
9 changes: 6 additions & 3 deletions examples/raw_gui_click.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""CDP Mode for bypassing bot-detection & CAPTCHAs.
Note: sb.uc_gui_click_captcha() requires PyAutoGUI,
which is installed automatically if not already."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/form_turnstile"
sb.activate_cdp_mode(url)
sb.activate_cdp_mode()
sb.open("seleniumbase.io/apps/form_turnstile")
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "test@test.test")
sb.press_keys("#phone", "1-555-555-5555")
Expand All @@ -14,7 +17,7 @@
sb.click('input[value="cc"] + span')
sb.scroll_to('div[class*="cf-turnstile"]')
sb.scroll_down(40)
sb.uc_gui_click_captcha()
sb.uc_gui_click_captcha() # PyAutoGUI mouse click
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
Expand Down
8 changes: 3 additions & 5 deletions examples/raw_hobbit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/hobbit/login"
sb.uc_open_with_disconnect(url, 2.2)
sb.uc_gui_press_keys("\t ")
sb.reconnect(1.5)
sb.activate_cdp_mode()
sb.open("https://seleniumbase.io/hobbit/login")
sb.click("button span#mySpan")
sb.assert_text("Welcome to Middle Earth!", "h1")
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
Expand Down
1 change: 0 additions & 1 deletion examples/raw_parameter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
sb._crumbs = False
sb._final_debug = False
sb.esc_end = False
sb.use_wire = False
sb.enable_3d_apis = False
sb.window_position = None
sb.window_size = None
Expand Down
2 changes: 2 additions & 0 deletions examples/raw_uc_events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""NOTE: This uses plain UC Mode, which was replaced by UC + CDP Mode.
PyAutoGUI is installed automatically for uc_gui methods if not already."""
from rich.pretty import pprint
from seleniumbase import SB

Expand Down
5 changes: 4 additions & 1 deletion examples/raw_uc_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""SB Manager using UC Mode for evading bot-detection."""
"""SB Manager using UC Mode for evading bot-detection.
Note that plain UC Mode was replaced by the newer CDP Mode:
Instead of uc_open_with_reconnect, use activate_cdp_mode().
Instead of uc_gui_click_captcha(), use solve_captcha()."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
Expand Down
Loading