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
10 changes: 6 additions & 4 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
card_info = 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
hotels = sb.cdp.select_all(card_info)
print("Hyatt Hotels in %s:" % location)
print("(" + sb.cdp.get_text("ul.b-color_text-white") + ")")
print("(" + sb.cdp.get_text('span[class*="summary_destination"]') + ")")
if len(hotels) == 0:
print("No availability over the selected dates!")
for hotel in hotels:
Expand Down Expand Up @@ -331,12 +331,13 @@ with SB(uc=True, test=True, locale="en", pls="none") as sb:
url = "https://www.nike.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.click('[data-testid="user-tools-container"] search')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
sb.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.cdp.select_all('ul[data-testid*="products"] figure .details')
details = 'ul[data-testid*="products"] figure .details'
elements = sb.select_all(details)
if elements:
print('**** Found results for "%s": ****' % search)
for element in elements:
Expand Down Expand Up @@ -528,6 +529,7 @@ sb.cdp.assert_in(first, second)
sb.cdp.assert_not_in(first, second)
sb.cdp.scroll_into_view(selector)
sb.cdp.scroll_to_y(y)
sb.cdp.scroll_by_y(y)
sb.cdp.scroll_to_top()
sb.cdp.scroll_to_bottom()
sb.cdp.scroll_up(amount=25)
Expand Down
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_cdp_copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
sb.wait_for_element_absent(stop_button, timeout=50)
sb.wait_for_element(thumbs_up, timeout=20)
sb.sleep(0.6)
sb.click('button[data-testid*="scroll-to-bottom"]')
scroll = 'button[data-testid*="scroll-to-bottom"]'
sb.click_if_visible(scroll)
sb.sleep(2.2)
folder = "downloaded_files"
file_name = "copilot_results.html"
Expand Down
30 changes: 21 additions & 9 deletions examples/cdp_mode/raw_cdp_kohls.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
from seleniumbase import sb_cdp

url = "https://www.kohls.com/"
sb = sb_cdp.Chrome(url, locale="en", guest=True)
sb = sb_cdp.Chrome(url, locale="en", ad_block=True)
sb.sleep(2.8)
search = "Mickey Mouse 100 friends teal pillow"
required_text = "Mickey"
search = "Mickey Mouse Blanket"
req_1 = "Mickey"
req_2 = "Blanket"
sb.press_keys('input[name="search"]', search + "\n")
sb.sleep(5)
for item in sb.find_elements("div.products-container-right"):
item_selector = 'div[data-testid*="wallet-wrapper"]'
if not sb.is_element_present(item_selector):
item_selector = "li.products_grid"
for item in sb.find_elements(item_selector):
if "Sponsored" in item.text:
item.remove_from_dom()
sb.remove_elements("#tce-sticky-wrapper")
sb.remove_elements("li.sponsored-product")
sb.remove_elements("#tce-dec-ces-3-banner")
print('*** Kohls Search for "%s":' % search)
for item in sb.find_elements("ul.products a img"):
print(' (Results must contain "%s" and "%s".)' % (req_1, req_2))
title_selector = "div.prod_nameBlock p"
if not sb.is_element_present(title_selector):
title_selector = 'a[class*="sm:text"][href*="/product/"]'
for item in sb.find_elements(title_selector):
if item:
item.flash(color="44CC88")
title = item.get_attribute("title")
if title and required_text in title:
print("* " + title)
sb.sleep(0.1)
title = item.text
if title:
if (
req_1.lower() in title.lower()
and req_2.lower() in title.lower()
):
print("* " + title)
sb.sleep(0.1)
sb.sleep(1)
sb.driver.stop()
6 changes: 4 additions & 2 deletions examples/cdp_mode/raw_cdp_nike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

url = "https://www.nike.com/"
sb = sb_cdp.Chrome(url)
sb.click('div[data-testid="user-tools-container"]')
sb.sleep(1.2)
sb.click('[data-testid="user-tools-container"] search')
sb.sleep(1)
search = "Pegasus"
sb.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.select_all('ul[data-testid*="products"] figure .details')
details = 'ul[data-testid*="products"] figure .details'
elements = sb.select_all(details)
if elements:
print('**** Found results for "%s": ****' % search)
for element in elements:
Expand Down
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
sb.wait_for_element_absent(stop_button, timeout=50)
sb.wait_for_element(thumbs_up, timeout=20)
sb.sleep(0.6)
sb.click('button[data-testid*="scroll-to-bottom"]')
scroll = 'button[data-testid*="scroll-to-bottom"]'
sb.click_if_visible(scroll)
sb.sleep(2.2)
folder = "downloaded_files"
file_name = "copilot_results.html"
Expand Down
20 changes: 20 additions & 0 deletions examples/cdp_mode/raw_form_turnstile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/form_turnstile"
sb.activate_cdp_mode(url)
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "test@test.test")
sb.press_keys("#phone", "1-555-555-5555")
sb.click('[for="date"]')
sb.click("td.is-today button")
sb.click('div[class="select-wrapper"] input')
sb.click('span:contains("9:00 PM")')
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.scroll_down(40)
sb.uc_gui_click_captcha()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
sb.highlight('button:contains("Success!")')
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
card_info = 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
hotels = sb.cdp.select_all(card_info)
print("Hyatt Hotels in %s:" % location)
print("(" + sb.cdp.get_text("ul.b-color_text-white") + ")")
print("(" + sb.cdp.get_text('span[class*="summary_destination"]') + ")")
if len(hotels) == 0:
print("No availability over the selected dates!")
for hotel in hotels:
Expand Down
28 changes: 20 additions & 8 deletions examples/cdp_mode/raw_kohls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@
url = "https://www.kohls.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.6)
search = "Mickey Mouse 100 friends teal pillow"
required_text = "Mickey"
search = "Mickey Mouse Blanket"
req_1 = "Mickey"
req_2 = "Blanket"
sb.cdp.press_keys('input[name="search"]', search + "\n")
sb.sleep(5)
for item in sb.cdp.find_elements("div.products-container-right"):
item_selector = 'div[data-testid*="wallet-wrapper"]'
if not sb.is_element_present(item_selector):
item_selector = "li.products_grid"
for item in sb.cdp.find_elements(item_selector):
if "Sponsored" in item.text:
item.remove_from_dom()
sb.cdp.remove_elements("#tce-sticky-wrapper")
sb.cdp.remove_elements("li.sponsored-product")
sb.cdp.remove_elements("#tce-dec-ces-3-banner")
print('*** Kohls Search for "%s":' % search)
for item in sb.cdp.find_elements("ul.products a img"):
print(' (Results must contain "%s" and "%s".)' % (req_1, req_2))
title_selector = "div.prod_nameBlock p"
if not sb.is_element_present(title_selector):
title_selector = 'a[class*="sm:text"][href*="/product/"]'
for item in sb.cdp.find_elements(title_selector):
if item:
item.flash(color="44CC88")
title = item.get_attribute("title")
if title and required_text in title:
print("* " + title)
sb.sleep(0.1)
title = item.text
if title:
if (
req_1.lower() in title.lower()
and req_2.lower() in title.lower()
):
print("* " + title)
sb.sleep(0.1)
sb.sleep(1)
7 changes: 4 additions & 3 deletions examples/cdp_mode/raw_nike.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
url = "https://www.nike.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.click('[data-testid="user-tools-container"] search')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
sb.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.cdp.select_all('ul[data-testid*="products"] figure .details')
details = 'ul[data-testid*="products"] figure .details'
elements = sb.select_all(details)
if elements:
print('**** Found results for "%s": ****' % search)
for element in elements:
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_res_nike.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def receive_handler(event: mycdp.network.ResponseReceived):
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)
sb.sleep(2.5)
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.cdp.click('[data-testid="user-tools-container"] search')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
Expand Down
3 changes: 2 additions & 1 deletion examples/locale_code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def test_locale_code(self):
language_info = self.get_text(
"settings-ui::shadow "
"settings-main::shadow "
"settings-basic-page::shadow "
"settings-languages-page-index::shadow "
"settings-languages-page::shadow "
"settings-section "
"#languagesSection div.start div"
)
print("Language info (chrome://settings/languages):")
Expand Down
14 changes: 7 additions & 7 deletions examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,9 @@ def test_presentation_4(self):
'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
)
hotels = sb.cdp.select_all(card_info)
destination_selector = 'span[class*="summary_destination"]'
print("Hyatt Hotels in %s:" % location)
print("(" + sb.cdp.get_text("ul.b-color_text-white") + ")")
print("(" + sb.cdp.get_text(destination_selector) + ")")
if len(hotels) == 0:
print("No availability over the selected dates!")
for hotel in hotels:
Expand Down Expand Up @@ -833,16 +834,15 @@ def test_presentation_4(self):
url = "https://www.nike.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.click('[data-testid="user-tools-container"] search')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
sb.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.cdp.select_all(
'ul[data-testid*="products"] figure .details'
)
details = 'ul[data-testid*="products"] figure .details'
elements = sb.select_all(details)
if elements:
print('\n\n**** Found results for "%s": ****' % search)
print('**** Found results for "%s": ****' % search)
for element in elements:
print("* " + element.text)
sb.sleep(2)
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/form_turnstile"
sb.uc_open_with_reconnect(url, 2)
sb.uc_open_with_reconnect(url, 1.1)
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "test@test.test")
sb.press_keys("#phone", "1-555-555-5555")
Expand Down
11 changes: 11 additions & 0 deletions examples/raw_gitlab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url)
sb.uc_gui_click_captcha() # Only if needed
sb.assert_element('label[for="user_login"]')
sb.assert_element('input[data-testid*="username"]')
sb.assert_element('input[data-testid*="password"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
33 changes: 18 additions & 15 deletions examples/raw_gui_click.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import sys
from seleniumbase import SB

# An bad UserAgent forces CAPTCHA-solving on macOS
agent = "cool"
if "linux" in sys.platform or "win32" in sys.platform:
agent = None # Use the default UserAgent

with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url)
sb.uc_gui_click_captcha() # Only if needed
sb.assert_element('label[for="user_login"]')
sb.assert_element('input[data-testid*="username"]')
sb.assert_element('input[data-testid*="password"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/form_turnstile"
sb.uc_open_with_reconnect(url, 1.1)
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "test@test.test")
sb.press_keys("#phone", "1-555-555-5555")
sb.click('[for="date"]')
sb.click("td.is-today button")
sb.click('div[class="select-wrapper"] input')
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_click_captcha()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
sb.highlight('button:contains("Success!")')
18 changes: 5 additions & 13 deletions examples/raw_pyautogui.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import sys
from seleniumbase import SB

# An bad UserAgent forces CAPTCHA-solving on macOS
agent = "cool"
if "linux" in sys.platform or "win32" in sys.platform:
agent = None # Use the default UserAgent

with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
url = "https://gitlab.com/users/sign_in"
with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/turnstile"
sb.uc_open_with_reconnect(url)
sb.uc_gui_handle_captcha() # Only if needed
sb.assert_element('label[for="user_login"]')
sb.assert_element('input[data-testid*="username"]')
sb.assert_element('input[data-testid*="password"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
5 changes: 2 additions & 3 deletions examples/test_hack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

class HackingTests(BaseCase):
def test_hack_search(self):
if self.headless:
if self.headless or self.browser != "chrome":
self.open_if_not_url("about:blank")
print("\n Skipping test in headless mode.")
self.skip('Skipping test in headless mode.')
self.skip('Skip test if headless or not chrome.')
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
Expand Down
9 changes: 9 additions & 0 deletions examples/test_todomvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@


class TodoMVC(BaseCase):
def setUp(self):
super().setUp()
self.open_new_window()

def tearDown(self):
self.save_teardown_screenshot()
self.driver.close()
super().tearDown()

@parameterized.expand([["jquery"], ["react"], ["vue"]])
def test_todomvc(self, framework):
self.open("https://todomvc.com/")
Expand Down
4 changes: 3 additions & 1 deletion examples/test_window_switching.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class TabSwitchingTests(BaseCase):
def test_switch_to_tabs(self):
self.open("about:blank")
self.get_new_driver()
self.open("data:text/html,<h1>Page A</h1>")
self.assert_text("Page A")
self.open_new_window()
Expand All @@ -17,6 +19,6 @@ def test_switch_to_tabs(self):
self.switch_to_window(0)
self.assert_text("Page A")
self.assert_text_not_visible("Page B")
self.switch_to_window(1)
self.switch_to_window(-1)
self.assert_text("Page B")
self.assert_text_not_visible("Page A")
Loading