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: 7 additions & 3 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,14 @@ with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
sb.sleep(1)
sb.sleep(1.2)
location = "Anaheim, CA, USA"
sb.type('input[id="search-term"]', location)
sb.sleep(1)
sb.sleep(1.2)
sb.click('li[data-js="suggestion"]')
sb.sleep(1)
sb.sleep(1.2)
sb.click("button.be-button-shop")
sb.sleep(6)
card_info = 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
Expand Down Expand Up @@ -381,6 +382,7 @@ sb.cdp.click_if_visible(selector)
sb.cdp.click_visible_elements(selector, limit=0)
sb.cdp.click_nth_element(selector, number)
sb.cdp.click_nth_visible_element(selector, number)
sb.cdp.click_with_offset(selector, x, y, center=False)
sb.cdp.click_link(link_text)
sb.cdp.go_back()
sb.cdp.go_forward()
Expand Down Expand Up @@ -475,11 +477,13 @@ sb.cdp.set_session_storage_item(key, value)
sb.cdp.set_attributes(selector, attribute, value)
sb.cdp.is_attribute_present(selector, attribute, value=None)
sb.cdp.is_online()
sb.cdp.solve_captcha()
sb.cdp.gui_press_key(key)
sb.cdp.gui_press_keys(keys)
sb.cdp.gui_write(text)
sb.cdp.gui_click_x_y(x, y, timeframe=0.25)
sb.cdp.gui_click_element(selector, timeframe=0.25)
sb.cdp.gui_click_with_offset(selector, x, y, timeframe=0.25, center=False)
sb.cdp.gui_click_captcha()
sb.cdp.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.35)
sb.cdp.gui_drag_and_drop(drag_selector, drop_selector, timeframe=0.35)
Expand Down
6 changes: 2 additions & 4 deletions examples/cdp_mode/raw_antibot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
sb.activate_cdp_mode(url)
sb.press_keys("input#username", "demo_user")
sb.press_keys("input#password", "secret_pass")
x, y = sb.cdp.get_gui_element_center("button#myButton")
sb.uc_gui_click_x_y(x, y)
sb.click("button#myButton")
sb.sleep(1.5)
x, y = sb.cdp.get_gui_element_center("a#log-in")
sb.uc_gui_click_x_y(x, y)
sb.click("a#log-in")
sb.assert_text("Welcome!", "h1")
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
Expand Down
4 changes: 2 additions & 2 deletions examples/cdp_mode/raw_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ async def main():
where_to = 'div[data-automation*="experiences"] input'
button = 'button[data-automation*="experiences-search"]'
sb.wait_for_text("Where to?")
sb.gui_click_element(where_to)
sb.click(where_to)
sb.press_keys(where_to, location)
sb.sleep(1)
sb.gui_click_element(button)
sb.click(button)
sb.sleep(3)
print(sb.get_title())
print("************")
Expand Down
35 changes: 35 additions & 0 deletions examples/cdp_mode/raw_canvas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Use SeleniumBase to interact with "canvas" elements."""
from seleniumbase import SB


def get_canvas_pixel_colors_at_top_left(sb):
# Return the RGB colors of the canvas's top left pixel
color = sb.cdp.evaluate(
"document.querySelector('canvas').getContext('2d')"
".getImageData(%s,%s,1,1).data;" % (0, 0)
)
return [color["0"], color["1"], color["2"]]


with SB(uc=True, test=True) as sb:
# Testing sb.cdp.click_with_offset()
url = "https://seleniumbase.io/canvas/"
sb.activate_cdp_mode(url)
sb.assert_title_contains("Canvas")
sb.highlight("canvas")
rgb = get_canvas_pixel_colors_at_top_left(sb)
sb.assert_equal(rgb, [221, 242, 231]) # Looks greenish
sb.cdp.click_with_offset("canvas", 500, 350)
sb.highlight("canvas", loops=5)
rgb = get_canvas_pixel_colors_at_top_left(sb)
sb.assert_equal(rgb, [39, 43, 56]) # Blue by hamburger

with SB(uc=True, test=True) as sb:
# Testing sb.cdp.gui_click_with_offset()
url = "https://seleniumbase.io/other/canvas"
sb.activate_cdp_mode(url)
sb.assert_title_contains("Canvas")
sb.cdp.gui_click_with_offset("canvas", 0, 0, center=True)
sb.sleep(1)
sb.uc_gui_press_key("ENTER")
sb.sleep(0.5)
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_cdp_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
print(sb.get_current_url())
sb.type("input#username", "demo_user")
sb.type("input#password", "secret_pass")
sb.cdp.gui_click_element("button")
sb.click("button")
sb.sleep(1)
sb.cdp.gui_click_element("a#log-in")
sb.click("a#log-in")
sb.assert_text("Welcome!", "h1")
sb.sleep(2)
sb.switch_to_driver(driver2)
sb.assert_url_contains("hobbit")
print(sb.get_current_url())
sb.cdp.gui_click_element("button")
sb.click("button")
sb.assert_text("Welcome to Middle Earth!")
sb.click("img")
sb.sleep(3)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_cdp_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = "https://gitlab.com/users/sign_in"
sb = sb_cdp.Chrome(url, incognito=True)
sb.sleep(2.2)
sb.gui_click_captcha()
sb.solve_captcha()
sb.highlight('h1:contains("GitLab")')
sb.highlight('button:contains("Sign in")')
sb.driver.stop()
9 changes: 5 additions & 4 deletions examples/cdp_mode/raw_cdp_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
sb = sb_cdp.Chrome(url, locale="en", guest=True)
sb.sleep(4.2)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
sb.sleep(1)
sb.sleep(1.2)
location = "Anaheim, CA, USA"
sb.type('input[id="search-term"]', location)
sb.sleep(1)
sb.sleep(1.2)
sb.click('li[data-js="suggestion"]')
sb.sleep(1)
sb.sleep(1.2)
sb.click("button.be-button-shop")
sb.sleep(6)
card_info = 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
hotels = sb.select_all(card_info)
print("Hyatt Hotels in %s:" % location)
print("(" + sb.get_text("ul.b-color_text-white") + ")")
print("(" + sb.get_text('span[class*="summary_destination"]') + ")")
if len(hotels) == 0:
print("No availability over the selected dates!")
for hotel in hotels:
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_cdp_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

url = "https://seleniumbase.io/apps/recaptcha"
sb = sb_cdp.Chrome(url)
sb.gui_click_captcha()
sb.solve_captcha()
sb.assert_element("img#captcha-success")
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_cdp_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

url = "https://seleniumbase.io/apps/turnstile"
sb = sb_cdp.Chrome(url)
sb.gui_click_captcha()
sb.solve_captcha()
sb.assert_element("img#captcha-success")
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
url = "www.planetminecraft.com/account"
driver.uc_activate_cdp_mode(url)
driver.sleep(1)
driver.uc_gui_click_captcha()
driver.cdp.solve_captcha()
driver.wait_for_element_absent("input[disabled]")
driver.sleep(2)
10 changes: 5 additions & 5 deletions examples/cdp_mode/raw_footlocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
url = "https://www.footlocker.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click_if_visible('button[id*="Agree"]')
sb.click_if_visible('button[id*="Agree"]')
sb.sleep(1.5)
sb.cdp.mouse_click('input[name="query"]')
sb.click('input[name="query"]')
sb.sleep(1.5)
search = "Nike Shoes"
sb.cdp.press_keys('input[name="query"]', search)
sb.press_keys('input[name="query"]', search)
sb.sleep(2.5)
sb.cdp.mouse_click('ul[id*="typeahead"] li div')
sb.click('ul[id*="typeahead"] li div')
sb.sleep(3.5)
elements = sb.cdp.select_all("a.ProductCard-link")
elements = sb.select_all("a.ProductCard-link")
if elements:
print('**** Found results for "%s": ****' % search)
for element in elements:
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_form_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.scroll_down(40)
sb.uc_gui_click_captcha()
sb.solve_captcha()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
url = "https://gitlab.com/users/sign_in"
sb.activate_cdp_mode(url)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.solve_captcha()
# (The rest is for testing and demo purposes)
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.assert_element('label[for="user_login"]')
Expand Down
11 changes: 6 additions & 5 deletions examples/cdp_mode/raw_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
sb.sleep(1)
sb.sleep(1.2)
location = "Anaheim, CA, USA"
sb.type('input[id="search-term"]', location)
sb.sleep(1)
sb.sleep(1.2)
sb.click('li[data-js="suggestion"]')
sb.sleep(1)
sb.sleep(1.2)
sb.click("button.be-button-shop")
sb.sleep(6)
card_info = 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_info"]'
hotels = sb.cdp.select_all(card_info)
hotels = sb.select_all(card_info)
print("Hyatt Hotels in %s:" % location)
print("(" + sb.cdp.get_text('span[class*="summary_destination"]') + ")")
print("(" + sb.get_text('span[class*="summary_destination"]') + ")")
if len(hotels) == 0:
print("No availability over the selected dates!")
for hotel in hotels:
Expand Down
5 changes: 1 addition & 4 deletions examples/cdp_mode/raw_indeed_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@
sb.click('button[type="submit"]')
sb.sleep(3.5)
selector = 'div[class*="pass-Captcha"]'
element_rect = sb.cdp.get_gui_element_rect(selector, timeout=1)
x = element_rect["x"] + 32
y = element_rect["y"] + 42
sb.cdp.gui_click_x_y(x, y)
sb.click_with_offset(selector, 32, 42)
sb.sleep(4.5)
20 changes: 20 additions & 0 deletions examples/cdp_mode/raw_nevada_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Business Entity Search / Bypasses hCaptcha."""
from seleniumbase import SB

with SB(uc=True, test=True, guest=True) as sb:
url = "https://www.nvsilverflume.gov/home"
sb.activate_cdp_mode(url)
sb.sleep(3)
sb.click('a[href="/redirectToCenuity/be"]')
sb.sleep(3.6)
sb.assert_element('label:contains("Business Search")')
sb.click('input#BusinessSearch_Index_rdContains')
sb.sleep(0.6)
name_field = 'input[data-automation-id*="EntityName"]'
search = "Laser Tag"
sb.press_keys(name_field, search + "\n")
sb.sleep(6.5)
print('*** Business Search for "%s":' % search)
businesses = sb.select_all("td a[onclick]")
for business in businesses:
print(business.text)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_planetmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
url = "www.planetminecraft.com/account/sign_in/"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.uc_gui_click_captcha()
sb.solve_captcha()
sb.wait_for_element_absent("input[disabled]")
sb.sleep(2)
18 changes: 10 additions & 8 deletions examples/cdp_mode/raw_priceline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
url = "https://www.priceline.com"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click('input[name="endLocation"]')
sb.sleep(1)
location = "Portland, OR, USA"
sb.click('input[name="endLocation"]')
sb.sleep(1.2)
location = "Portland, Oregon, US"
selection = "Oregon, United States" # (Dropdown option)
sb.cdp.press_keys('input[name="endLocation"]', location)
sb.sleep(1)
sb.press_keys('input[name="endLocation"]', location)
sb.sleep(1.5)
sb.click_if_visible('input[name="endLocation"]')
sb.sleep(0.5)
sb.cdp.click(selection)
sb.sleep(0.6)
sb.click(selection)
sb.sleep(1.5)
sb.cdp.click('button[aria-label="Dismiss calendar"]')
sb.click('button[aria-label="Dismiss calendar"]')
sb.sleep(0.5)
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
sb.sleep(5.5)
if len(sb.cdp.get_tabs()) > 1:
sb.cdp.close_active_tab()
Expand Down
8 changes: 4 additions & 4 deletions examples/cdp_mode/raw_radwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
url = "https://www.radwell.com/en-US/Search/Advanced/"
sb.activate_cdp_mode(url)
sb.sleep(3)
sb.cdp.press_keys("form#basicsearch input", "821C-PM-111DA-142")
sb.press_keys("form#basicsearch input", "821C-PM-111DA-142")
sb.sleep(1)
sb.cdp.click('[value="Search Icon"]')
sb.click('[value="Search Icon"]')
sb.sleep(3)
sb.cdp.assert_text("MAC VALVES INC", "a.manufacturer-link")
sb.cdp.highlight("a.manufacturer-link")
sb.assert_text("MAC VALVES INC", "a.manufacturer-link")
sb.highlight("a.manufacturer-link")
sb.sleep(1)
17 changes: 17 additions & 0 deletions examples/cdp_mode/raw_seatgeek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from seleniumbase import SB

with SB(uc=True, test=True, guest=True) as sb:
url = "https://seatgeek.com/"
sb.activate_cdp_mode(url)
input_field = 'input[name="search"]'
sb.wait_for_element(input_field)
sb.sleep(1.6)
query = "Jerry Seinfeld"
sb.press_keys(input_field, query)
sb.sleep(1.6)
sb.click("li#active-result-item")
sb.sleep(4.2)
print('*** SeatGeek Search for "%s":' % query)
item_selector = '[data-testid="listing-item"]'
for item in sb.find_elements(item_selector):
print(item.text)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/turnstile"
sb.activate_cdp_mode(url)
sb.uc_gui_click_captcha()
sb.solve_captcha()
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
Loading