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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ from seleniumbase import SB
with SB(uc=True, test=True) as sb:
url = "https://google.com/ncr"
sb.activate_cdp_mode(url)
sb.click_if_visible('button:contains("Accept all")')
sb.type('[name="q"]', "SeleniumBase GitHub page")
sb.click('[value="Google Search"]')
sb.sleep(4) # The "AI Overview" sometimes loads
Expand Down
1 change: 1 addition & 0 deletions examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_google_dot_com(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.driver.get("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.assert_title_contains("Google")
self.sleep(0.05)
self.save_screenshot_to_logs() # ("./latest_logs" folder)
Expand Down
1 change: 1 addition & 0 deletions examples/boilerplates/samples/test_page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class GooglePage:
def go_to_google(self, sb):
sb.driver.get("https://google.com/ncr")
sb.click_if_visible('button:contains("Accept all")')

def assert_google_title(self, sb):
sb.assert_title_contains("Google")
Expand Down
3 changes: 2 additions & 1 deletion examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ sb.cdp.assert_equal(first, second)
sb.cdp.assert_not_equal(first, second)
sb.cdp.assert_in(first, second)
sb.cdp.assert_not_in(first, second)
sb.cdp.js_scroll_into_view(selector)
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 Expand Up @@ -730,6 +730,7 @@ element.flash(duration=0.5, color="EE4488")
element.focus()
element.gui_click(timeframe=0.25)
element.highlight_overlay()
element.is_in_viewport()
element.mouse_click()
element.mouse_drag(destination)
element.mouse_move()
Expand Down
8 changes: 5 additions & 3 deletions examples/cdp_mode/raw_homedepot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True) as sb:
with SB(uc=True, test=True, incognito=True) as sb:
url = "https://www.homedepot.com/"
sb.activate_cdp_mode(url)
sb.sleep(1.8)
sb.sleep(1.4)
sb.click_if_visible('[data-testid="CloseIcon"]', timeout=3)
sb.sleep(1.2)
search_box = "input#typeahead-search-field-input"
search = "Computer Chair"
category = "Gaming Chairs"
required_text = "Chair"
sb.click(search_box)
sb.sleep(1.2)
sb.sleep(0.8)
sb.press_keys(search_box, search)
sb.sleep(0.6)
sb.click("button#typeahead-search-icon-button")
Expand Down
9 changes: 3 additions & 6 deletions examples/cdp_mode/raw_priceline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
sb.sleep(0.6)
sb.sleep(0.8)
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(0.5)
sb.scroll_to_y(y * 200)
sb.sleep(0.4)
hotel_names = sb.find_elements('h3 div[class*="TitleName"]')
if not hotel_names:
hotel_names = sb.find_elements(
'a[data-autobot-element-id*="HOTEL_NAME"]'
)
hotel_names = sb.find_elements("h3.antialiased")
price_selector = '[class*="PriceWrap"] .relative > .items-center'
if sb.is_element_visible(price_selector):
hotel_prices = sb.find_elements(price_selector)
Expand All @@ -52,7 +50,6 @@
'span.text-priceSuper-heading4 + div > span'
)
print("Priceline Hotels in %s:" % location)
print(sb.get_text('[data-testid="POPOVER-DATE-PICKER"]'))
if len(hotel_names) == 0:
print("No availability over the selected dates!")
count = 0
Expand Down
3 changes: 2 additions & 1 deletion examples/cdp_mode/raw_stopandshop.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Test Stop & Shop search. Non-US IPs might be blocked."""
from seleniumbase import SB

with SB(uc=True, test=True, incognito=True) as sb:
with SB(uc=True, test=True, guest=True) as sb:
url = "https://stopandshop.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.6)
if not sb.is_element_present("#brand-logo_link"):
sb.refresh()
sb.sleep(2.6)
sb.wait_for_element("#brand-logo_link", timeout=3)
sb.click_if_visible("#optly-popup-refresh-btn")
query = "Fresh Turkey"
required_text = "Turkey"
search_box = 'input[type="search"]'
Expand Down
5 changes: 3 additions & 2 deletions examples/hack_the_planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_all_your_base_are_belong_to_us(self):
self.highlight("#shelf-2_section span", loops=6, scroll=False)

self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.hide_elements("iframe")
if self.is_element_visible('a[href*="about.google"]'):
self.set_text_content('a[href*="about.google"]', ayb)
Expand Down Expand Up @@ -191,7 +192,7 @@ def test_all_your_base_are_belong_to_us(self):
self.highlight("h1.article_title", loops=5, scroll=False)

self.open("https://kubernetes.io/")
self.set_text_content('nav a[href="/docs/"]', "ALL")
self.set_text_content('nav a[href="/docs/home/"]', "ALL")
self.set_text_content('nav a[href="/blog/"]', "YOUR")
self.set_text_content('nav a[href="/training/"]', "BASE")
self.set_text_content('nav a[href="/careers/"]', "ARE")
Expand All @@ -202,7 +203,7 @@ def test_all_your_base_are_belong_to_us(self):
if self.is_element_visible("h1"):
self.set_text_content("h1", aybabtu)
self.highlight("nav ul.navbar-nav", loops=3, scroll=False)
self.highlight('nav a[href="/docs/"]', loops=1, scroll=False)
self.highlight('nav a[href="/docs/home/"]', loops=1, scroll=False)
self.highlight('nav a[href="/blog/"]', loops=1, scroll=False)
self.highlight('nav a[href="/training/"]', loops=2, scroll=False)
self.highlight('nav a[href="/careers/"]', loops=1, scroll=False)
Expand Down
9 changes: 3 additions & 6 deletions examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,13 +799,11 @@ def test_presentation_4(self):
sb.sleep(0.6)
sb.sleep(0.8)
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(0.5)
sb.scroll_to_y(y * 200)
sb.sleep(0.4)
hotel_names = sb.find_elements('h3 div[class*="TitleName"]')
if not hotel_names:
hotel_names = sb.find_elements(
'a[data-autobot-element-id*="HOTEL_NAME"]'
)
hotel_names = sb.find_elements("h3.antialiased")
price_selector = '[class*="PriceWrap"] .relative > .items-center'
if sb.is_element_visible(price_selector):
hotel_prices = sb.find_elements(price_selector)
Expand All @@ -820,7 +818,6 @@ def test_presentation_4(self):
'span.text-priceSuper-heading4 + div > span'
)
print("Priceline Hotels in %s:" % location)
print(sb.get_text('[data-testid="POPOVER-DATE-PICKER"]'))
if len(hotel_names) == 0:
print("No availability over the selected dates!")
count = 0
Expand Down
1 change: 1 addition & 0 deletions examples/raw_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with SB(uc=True, test=True) as sb:
url = "https://google.com/ncr"
sb.activate_cdp_mode(url)
sb.click_if_visible('button:contains("Accept all")')
sb.type('[name="q"]', "SeleniumBase GitHub page")
sb.click('[value="Google Search"]')
sb.sleep(4) # The "AI Overview" sometimes loads
Expand Down
1 change: 1 addition & 0 deletions examples/raw_test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

with SB(uc=True, test=True) as sb:
sb.open("https://google.com/ncr")
sb.click_if_visible('button:contains("Accept all")')
sb.type('[name="q"]', "SeleniumBase on GitHub")
sb.click('[value="Google Search"]')
sb.highlight('a[href*="github.com/seleniumbase"]')
Expand Down
2 changes: 2 additions & 0 deletions examples/test_hack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_hack_search(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.hide_elements("iframe")
self.assert_element('[title="Search"]')
self.sleep(0.5)
Expand All @@ -25,6 +26,7 @@ def test_hack_search(self):
self.highlight("h1.b_logo", loops=8)
source = self.get_page_source()
self.assert_true("github.com/seleniumbase/SeleniumBase" in source)
self.internalize_links()
self.click('a:contains("seleniumbase/SeleniumBase")')
self.js_click('a[title="examples"]')
self.highlight('#repo-content-turbo-frame')
Expand Down
1 change: 1 addition & 0 deletions examples/tour_examples/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class MyTourClass(BaseCase):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open('https://google.com/ncr')
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('input[title="Search"]')
self.hide_elements("iframe")

Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/bootstrap_google_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_google_tour(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('[title="Search"]')
self.hide_elements("iframe")

Expand All @@ -33,9 +34,9 @@ def test_google_tour(self):
self.play_tour(interval=3) # Tour automatically continues after 3 sec

self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)
Expand Down
8 changes: 4 additions & 4 deletions examples/tour_examples/driverjs_maps_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class MyTestClass(BaseCase):
def test_create_tour(self):
self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element("#widget-zoom-out")
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)

Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/google_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_google_tour(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('[title="Search"]')
self.hide_elements("iframe")

Expand Down Expand Up @@ -39,9 +40,9 @@ def test_google_tour(self):
self.play_tour(interval=3) # Tour automatically continues after 3 sec

self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput")
self.wait_for_element("#minimap")
self.wait_for_element("#zoom")
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)
Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/hopscotch_google_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_google_tour(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('[title="Search"]')
self.hide_elements("iframe")

Expand All @@ -33,9 +34,9 @@ def test_google_tour(self):
self.play_tour(interval=3) # Tour automatically continues after 3 sec

self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)
Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/introjs_google_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_google_tour(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('[title="Search"]')
self.hide_elements("iframe")

Expand All @@ -33,9 +34,9 @@ def test_google_tour(self):
self.play_tour(interval=3) # Tour automatically continues after 3 sec

self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)
Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/maps_introjs_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
class MyTourClass(BaseCase):
def test_google_maps_tour(self):
self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)

self.create_tour(theme="introjs")
self.add_tour_step(
Expand Down
7 changes: 4 additions & 3 deletions examples/tour_examples/shepherd_google_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_google_tour(self):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.open("https://google.com/ncr")
self.click_if_visible('button:contains("Accept all")')
self.wait_for_element('[title="Search"]')
self.hide_elements("iframe")

Expand All @@ -33,9 +34,9 @@ def test_google_tour(self):
self.play_tour(interval=3) # Tour automatically continues after 3 sec

self.open("https://www.google.com/maps/@42.3591234,-71.0915634,15z")
self.wait_for_element("#searchboxinput", timeout=20)
self.wait_for_element("#minimap", timeout=20)
self.wait_for_element("#zoom", timeout=20)
self.wait_for_element('[name="q"]', timeout=20)
self.wait_for_element('[aria-label="Interactive map"]', timeout=20)
self.wait_for_element('[aria-label="Zoom in"]', timeout=20)
self.wait_for_element('[aria-label="Zoom out"]')
self.wait_for_element('[jsaction*="minimap.main;"]')
self.sleep(0.5)
Expand Down
3 changes: 2 additions & 1 deletion help_docs/cdp_mode_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ sb.cdp.assert_equal(first, second)
sb.cdp.assert_not_equal(first, second)
sb.cdp.assert_in(first, second)
sb.cdp.assert_not_in(first, second)
sb.cdp.js_scroll_into_view(selector)
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()
Expand Down Expand Up @@ -358,6 +358,7 @@ element.flash(duration=0.5, color="EE4488")
element.focus()
element.gui_click(timeframe=0.25)
element.highlight_overlay()
element.is_in_viewport()
element.mouse_click()
element.mouse_drag(destination)
element.mouse_move()
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.47.6"
__version__ = "4.47.7"
3 changes: 3 additions & 0 deletions seleniumbase/console_scripts/sb_mkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,9 @@ def main():
data.append(" if not self.undetectable:")
data.append(" self.get_new_driver(undetectable=True)")
data.append(' self.open("https://google.com/ncr")')
data.append(
" sb.click_if_visible('button:contains(\"Accept all\")')"
)
data.append(' self.assert_title_contains("Google")')
data.append(" self.save_screenshot_to_logs()")
data.append(' self.type(HomePage.search_box, "github.com")')
Expand Down
1 change: 1 addition & 0 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
cdp.assert_not_equal = CDPM.assert_not_equal
cdp.assert_in = CDPM.assert_in
cdp.assert_not_in = CDPM.assert_not_in
cdp.js_scroll_into_view = CDPM.js_scroll_into_view
cdp.scroll_into_view = CDPM.scroll_into_view
cdp.scroll_to_y = CDPM.scroll_to_y
cdp.scroll_by_y = CDPM.scroll_by_y
Expand Down
Loading