Add more examples

This commit is contained in:
Michael Mintz 2024-06-23 13:49:34 -04:00
parent 57a52c3fb0
commit 3e5a2c227a
6 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,15 @@
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
from seleniumbase import SB
with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/antibot/login"
sb.uc_open_with_disconnect(url, 2.15)
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.uc_gui_press_keys(["\t", "ENTER"]) # Multi-char keys
sb.reconnect(1.8)
sb.assert_text("Welcome!", "h1")
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")

11
examples/raw_block.py Normal file
View File

@ -0,0 +1,11 @@
"""If Brotector catches you, Gandalf blocks you!"""
from seleniumbase import SB
with SB(test=True) as sb:
url = "https://seleniumbase.io/hobbit/login"
sb.open(url)
sb.click_if_visible("button")
sb.assert_text("Gandalf blocked you!", "h1")
sb.click("img")
sb.highlight("h1")
sb.sleep(3) # Gandalf: "You Shall Not Pass!"

View File

@ -0,0 +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/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)

12
examples/raw_detection.py Normal file
View File

@ -0,0 +1,12 @@
"""The Brotector CAPTCHA in action."""
from seleniumbase import SB
with SB(test=True) as sb:
sb.open("https://seleniumbase.io/antibot/login")
sb.highlight("h4", loops=6)
sb.type("#username", "demo_user")
sb.type("#password", "secret_pass")
sb.click_if_visible("button span")
sb.highlight("label#pText")
sb.highlight("table#detections")
sb.sleep(4.4) # Add time to read the table

13
examples/raw_hobbit.py Normal file
View File

@ -0,0 +1,13 @@
"""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.assert_text("Welcome to Middle Earth!", "h1")
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
sb.click("img")
sb.sleep(5.888) # Cool animation happening now!

19
examples/raw_pyautogui.py Normal file
View File

@ -0,0 +1,19 @@
"""
UC Mode now has uc_gui_handle_cf(), which uses PyAutoGUI.
An incomplete UserAgent is used to force CAPTCHA-solving.
"""
import sys
from seleniumbase import SB
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
if "linux" in sys.platform:
agent = None # Use the default UserAgent
with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
url = "https://www.virtualmanager.com/en/login"
sb.uc_open_with_reconnect(url, 4)
sb.uc_gui_handle_cf() # Ready if needed!
sb.assert_element('input[name*="email"]')
sb.assert_element('input[name*="login"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")