Update examples

This commit is contained in:
Michael Mintz 2024-04-25 23:41:43 -04:00
parent e214132fc7
commit cd3f13fe22
4 changed files with 24 additions and 3 deletions

View File

@ -3,7 +3,8 @@ from seleniumbase import Driver
driver = Driver(uc=True, log_cdp=True)
try:
driver.uc_open_with_reconnect("https://seleniumbase.io/apps/turnstile")
url = "seleniumbase.io/apps/turnstile"
driver.uc_open_with_reconnect(url, 2)
driver.switch_to_frame("iframe")
driver.uc_click("span.mark")
driver.sleep(3)

19
examples/raw_cookies.py Normal file
View File

@ -0,0 +1,19 @@
"""A SeleniumBase test that loads cookies to bypass login."""
from seleniumbase import SB
# Log in to Swag Labs and save cookies
with SB(test=True) as sb:
sb.open("https://www.saucedemo.com")
sb.wait_for_element("div.login_logo")
sb.type("#user-name", "standard_user")
sb.type("#password", "secret_sauce")
sb.click('input[type="submit"]')
sb.highlight("div.inventory_list", loops=6)
sb.save_cookies(name="cookies.txt")
# Load previously saved cookies to bypass login
with SB(test=True) as sb:
sb.open("https://www.saucedemo.com")
sb.load_cookies(name="cookies.txt")
sb.open("https://www.saucedemo.com/inventory.html")
sb.highlight("div.inventory_list", loops=12)

View File

@ -42,4 +42,4 @@ class TestGeolocation(BaseCase):
self.assert_url_contains("48.87645/2.26340")
self.save_screenshot_to_logs()
if self.headed:
self.sleep(2.5)
self.sleep(4)

View File

@ -21,7 +21,8 @@ class CDPTests(BaseCase):
def test_display_cdp_events(self):
if not (self.undetectable and self.uc_cdp_events):
self.get_new_driver(undetectable=True, uc_cdp_events=True)
self.driver.uc_open_with_reconnect("seleniumbase.io/apps/turnstile")
url = "seleniumbase.io/apps/turnstile"
self.driver.uc_open_with_reconnect(url, 2)
self.add_cdp_listener()
self.click_turnstile_and_verify()
self.sleep(1)