Skip to content

Commit

Permalink
Merge pull request #3244 from seleniumbase/cdp-mode-patch-7
Browse files Browse the repository at this point in the history
CDP Mode - Patch 7
  • Loading branch information
mdmintz authored Nov 4, 2024
2 parents 57df468 + 3fee25d commit 44c5164
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_easyjet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
sb.sleep(3.5)
sb.connect()
sb.sleep(0.5)
if "easyjet.com" not in sb.get_current_url():
if "/buy/flights" not in sb.get_current_url():
sb.driver.close()
sb.switch_to_newest_window()
days = sb.find_elements("div.flight-grid-day")
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'div[data-booking-status="BOOKABLE"] [class*="HotelCard_header"]'
)
hotel_prices = sb.cdp.select_all(
'div[data-booking-status="BOOKABLE"] div.rate-currency'
'div[data-booking-status="BOOKABLE"] div.rate'
)
sb.assert_true(len(hotel_names) == len(hotel_prices))
print("Hyatt Hotels in %s:" % location)
Expand Down
17 changes: 17 additions & 0 deletions examples/cdp_mode/raw_nike.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, locale_code="en") as sb:
url = "https://www.nike.com/"
sb.activate_cdp_mode(url)
sb.sleep(3)
sb.cdp.gui_click_element('div[data-testid="user-tools-container"]')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.cdp.select_all('ul[data-testid*="products"] figure .details')
if elements:
print('**** Found results for "%s": ****' % search)
for element in elements:
print("* " + element.text)
sb.sleep(2)
2 changes: 1 addition & 1 deletion examples/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_github(self):
self.assert_text("SeleniumBase", "strong a")
self.js_click('a[title="seleniumbase"]')
self.slow_click('td[class*="large"] a[title="fixtures"]')
self.assert_element('td[class*="large"] a[title="base_case.py"]')
self.highlight('td[class*="large"] a[title="base_case.py"]', loops=8)
12 changes: 4 additions & 8 deletions examples/hack_the_planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HackTests(BaseCase):
def test_all_your_base_are_belong_to_us(self):
self.set_window_size(1220, 740)
self.set_window_size(1250, 740)
ayb = "ALL YOUR BASE"
abtu = "ARE BELONG TO US"
aybabtu = "%s %s" % (ayb, abtu)
Expand All @@ -22,8 +22,7 @@ def test_all_your_base_are_belong_to_us(self):
self.set_text_content("#n-currentevents a", "BASE")
self.set_text_content("#n-randompage a", "ARE")
self.set_text_content("#n-aboutsite a", "BELONG")
self.set_text_content("#n-contactpage a", "TO")
self.set_text_content("#n-sitesupport a", "US")
self.set_text_content("#n-contactpage a", "TO US")
self.highlight("h1#firstHeading", loops=5, scroll=False)
zoom_in = "#ca-history a{zoom: 1.8;-moz-transform: scale(1.8);}"
self.add_css_style(zoom_in)
Expand Down Expand Up @@ -86,11 +85,8 @@ def test_all_your_base_are_belong_to_us(self):
self.highlight('form[role="search"]', loops=8)

self.open("https://github.com/features/actions")
self.set_text_content("h2.h2-mktg", aybabtu)
self.set_text_content("a.btn-large-mktg", aybabtu)
self.highlight("h2.h2-mktg", loops=8, scroll=False)
self.scroll_to("h2.h2-mktg")
self.highlight("a.btn-large-mktg", loops=8, scroll=False)
self.set_text_content("#hero-section-brand-heading", aybabtu)
self.highlight("#hero-section-brand-heading", loops=14, scroll=False)

self.open("https://dev.to/top/infinity")
self.click_if_visible('button[aria-label="Close campaign banner"]')
Expand Down
2 changes: 2 additions & 0 deletions examples/raw_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/recaptcha"
sb.activate_cdp_mode(url)
sb.uc_gui_handle_captcha() # Try with TAB + SPACEBAR
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/recaptcha"
sb.activate_cdp_mode(url)
sb.uc_gui_click_captcha('iframe[src*="/recaptcha/"]')
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pyotp==2.9.0
python-xlib==0.33;platform_system=="Linux"
markdown-it-py==3.0.0
mdurl==0.1.2
rich==13.9.3
rich==13.9.4

# --- Testing Requirements --- #
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
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.32.6"
__version__ = "4.32.7"
6 changes: 6 additions & 0 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,10 @@ def _set_chrome_options(
binary_loc = detect_b_ver.get_binary_location(br_app, True)
if os.path.exists(binary_loc):
binary_location = binary_loc
elif os.path.exists("/usr/bin/google-chrome-stable"):
binary_location = "/usr/bin/google-chrome-stable"
elif os.path.exists("/usr/bin/google-chrome"):
binary_location = "/usr/bin/google-chrome"
extra_disabled_features = []
if chromium_arg:
# Can be a comma-separated list of Chromium args or a list
Expand Down Expand Up @@ -2228,6 +2232,8 @@ def _set_chrome_options(
chrome_options.add_argument("--wm-window-animations-disabled")
chrome_options.add_argument("--enable-privacy-sandbox-ads-apis")
chrome_options.add_argument("--disable-background-timer-throttling")
# Prevent new tabs opened by Selenium from being blocked:
chrome_options.add_argument("--disable-popup-blocking")
# Skip remaining options that trigger anti-bot services
return chrome_options
chrome_options.add_argument("--test-type")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
'python-xlib==0.33;platform_system=="Linux"',
'markdown-it-py==3.0.0',
'mdurl==0.1.2',
'rich==13.9.3',
'rich==13.9.4',
],
extras_require={
# pip install -e .[allure]
Expand Down

0 comments on commit 44c5164

Please sign in to comment.