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
13 changes: 10 additions & 3 deletions examples/cdp_mode/raw_cf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
"""Using CDP Mode to bypass CAPTCHAs in different ways."""
from seleniumbase import SB

with SB(uc=True, test=True, guest=True) as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(3)
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
sb.uc_gui_handle_captcha() # PyAutoGUI Tabs + Spacebar
sb.sleep(3)

with SB(uc=True, test=True, guest=True) as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(4)
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
sb.uc_gui_click_captcha() # PyAutoGUI mouse click
sb.sleep(3)

with SB(uc=True, test=True, guest=True) as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(4)
sb.solve_captcha() # CDP Input.dispatchMouseEvent
sb.sleep(3)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_nevada_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Business Entity Search / Bypasses hCaptcha."""
from seleniumbase import SB

with SB(uc=True, test=True, guest=True) as sb:
with SB(uc=True, test=True) as sb:
url = "https://www.nvsilverflume.gov/home"
sb.activate_cdp_mode(url)
sb.sleep(3)
Expand Down
7 changes: 3 additions & 4 deletions examples/cdp_mode/raw_pixelscan.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from seleniumbase import SB

with SB(uc=True, test=True, incognito=True) as sb:
with SB(uc=True, test=True, incognito=True, ad_block=True) as sb:
url = "https://pixelscan.net/fingerprint-check"
sb.activate_cdp_mode(url)
sb.remove_element("#headerBanner")
sb.wait_for_element("pxlscn-dynamic-ad")
sb.sleep(0.5)
sb.remove_elements("pxlscn-dynamic-ad")
sb.sleep(2)
sb.assert_text("No masking detected", "pxlscn-fingerprint-masking")
sb.assert_text("No automated behavior", "pxlscn-bot-detection")
sb.cdp.highlight('span:contains("is consistent")')
sb.sleep(1)
sb.cdp.highlight("pxlscn-fingerprint-masking p")
sb.sleep(1)
sb.cdp.highlight("pxlscn-bot-detection p")
sb.sleep(1)
sb.cdp.highlight('span.status-success')
sb.sleep(2)
49 changes: 34 additions & 15 deletions examples/cdp_mode/raw_priceline.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
"""Priceline does a lot of A/B testing. Selectors change frequently."""
from seleniumbase import SB

with SB(uc=True, test=True, locale="en", guest=True, ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", guest=True, pls="none") as sb:
url = "https://www.priceline.com"
sb.activate_cdp_mode(url)
sb.sleep(1.8)
sb.click('input[name="endLocation"]')
sb.sleep(2.6)
input_selector = '[name="endLocation"]'
if not sb.is_element_present(input_selector):
input_selector = "div.location-input input"
sb.click(input_selector)
sb.sleep(1.2)
location = "Portland, OR"
selection = "Oregon, United States" # (Dropdown option)
sb.press_keys('input[name="endLocation"]', location)
sb.sleep(0.5)
sb.click_if_visible('input[name="endLocation"]')
sb.sleep(0.5)
sb.press_keys(input_selector, location)
sb.sleep(0.6)
sb.click(selection)
sb.sleep(0.4)
sb.scroll_down(25)
sb.click_if_visible('button[aria-label="Dismiss calendar"]')
sb.click_if_visible("div.sidebar-iframe-close")
sb.click_if_visible('div[aria-label="Close Modal"]')
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
sb.sleep(0.4)
calendar_close = 'button[aria-label="Dismiss calendar"]'
if not sb.is_element_visible(calendar_close):
calendar_close = '[data-mode="range"] span.px-1'
sb.click(calendar_close)
sb.sleep(0.6)
sb.click('form button[type="submit"]')
sb.sleep(4.8)
if len(sb.cdp.get_tabs()) > 1:
sb.cdp.close_active_tab()
Expand All @@ -27,13 +33,24 @@
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(0.5)
hotel_names = sb.find_elements('a[data-autobot-element-id*="HOTEL_NAME"]')
if sb.is_element_visible('[font-size="4,,,5"]'):
hotel_prices = sb.find_elements('[font-size="4,,,5"]')
else:
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"]'
)
price_selector = '[class*="PriceWrap"] .relative > .items-center'
if sb.is_element_visible(price_selector):
hotel_prices = sb.find_elements(price_selector)
elif sb.is_element_present(
'[font-size="12px"] + [font-size="20px"]'
):
hotel_prices = sb.find_elements(
'[font-size="12px"] + [font-size="20px"]'
)
else:
hotel_prices = sb.find_elements(
'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:
Expand All @@ -43,4 +60,6 @@
if hotel_prices[i] and hotel_prices[i].text:
count += 1
hotel_price = "$" + hotel_prices[i].text
if hotel_price.startswith("$$ "):
hotel_price = hotel_price.replace("$$ ", "$")
print("* %s: %s => %s" % (count, hotel.text, hotel_price))
4 changes: 3 additions & 1 deletion examples/cdp_mode/raw_totalwine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
sb.sleep(1.2)
sb.press_keys(search_box, search)
sb.sleep(0.6)
sb.click_if_visible('button[aria-label="Close modal"]')
sb.click('button[data-at="header-search-button"]')
sb.sleep(1.8)
sb.click_if_visible('button[aria-label="Close modal"]')
sb.click('img[data-at="product-search-productimage"]')
sb.sleep(2.2)
print('*** Total Wine Search for "%s":' % search)
print(sb.get_text('h1[data-at="product-name-title"]'))
print(sb.get_text('span[data-at="product-mix6price-text"]'))
print(sb.get_text('span[data-at="product-mixCaseprice-text"]'))
print("Product Highlights:")
print(sb.get_text('p[class*="productInformationReview"]'))
print("Product Details:")
Expand Down
10 changes: 6 additions & 4 deletions examples/cdp_mode/raw_united.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.united.com/en/us"
sb.activate_cdp_mode(url)
sb.sleep(2.6)
sb.sleep(3.5)
origin_input = 'input[placeholder="Origin"]'
origin = "New York, NY"
origin = "JFK"
destination_input = 'input[placeholder="Destination"]'
destination = "Orlando, FL"
destination = "MCO"
sb.wait_for_element(origin_input, timeout=20)
sb.sleep(0.5)
sb.click(origin_input)
sb.sleep(0.5)
sb.type(origin_input, origin)
Expand Down Expand Up @@ -39,7 +41,7 @@
part_3 = flight.text.split(" Destination")[-1].split(" Aircraft")[0]
parts = "%s - %s %s" % (part_1, part_2, part_3)
print("* " + parts)
for category in ["ECONOMY", "ECONOMY-UNRESTRICTED"]:
for category in ["ECONOMY"]:
prices = sb.find_elements('[aria-describedby="%s"]' % category)
full_prices = []
for item in prices:
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_zoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
items = sb.find_elements('[data-za="search-product-card"]')
for item in items:
if required_text in item.text:
description = item.querySelector('[data-za="product-title"]')
description = item.querySelector("h2")
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
print("* " + description.text)
Expand Down
54 changes: 34 additions & 20 deletions examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,26 +769,29 @@ def test_presentation_4(self):
)
self.begin_presentation(filename="uc_presentation.html")

with SB(
uc=True, test=True, locale="en", guest=True, ad_block=True
) as sb:
with SB(uc=True, test=True, locale="en", guest=True, pls="none") as sb:
url = "https://www.priceline.com"
sb.activate_cdp_mode(url)
sb.sleep(1.8)
sb.click('input[name="endLocation"]')
sb.sleep(2.6)
input_selector = '[name="endLocation"]'
if not sb.is_element_present(input_selector):
input_selector = "div.location-input input"
sb.click(input_selector)
sb.sleep(1.2)
location = "Portland, Oregon, US"
location = "Portland, OR"
selection = "Oregon, United States" # (Dropdown option)
sb.press_keys('input[name="endLocation"]', location)
sb.sleep(0.5)
sb.click_if_visible('input[name="endLocation"]')
sb.sleep(0.5)
sb.press_keys(input_selector, location)
sb.sleep(0.6)
sb.click(selection)
sb.sleep(0.4)
sb.scroll_down(25)
sb.click_if_visible('button[aria-label="Dismiss calendar"]')
sb.click_if_visible("div.sidebar-iframe-close")
sb.click_if_visible('div[aria-label="Close Modal"]')
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
sb.sleep(0.4)
calendar_close = 'button[aria-label="Dismiss calendar"]'
if not sb.is_element_visible(calendar_close):
calendar_close = '[data-mode="range"] span.px-1'
sb.click(calendar_close)
sb.sleep(0.6)
sb.click('form button[type="submit"]')
sb.sleep(4.8)
if len(sb.cdp.get_tabs()) > 1:
sb.cdp.close_active_tab()
Expand All @@ -798,15 +801,24 @@ def test_presentation_4(self):
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(0.5)
hotel_names = sb.find_elements(
'a[data-autobot-element-id*="HOTEL_NAME"]'
)
if sb.is_element_visible('[font-size="4,,,5"]'):
hotel_prices = sb.find_elements('[font-size="4,,,5"]')
else:
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"]'
)
price_selector = '[class*="PriceWrap"] .relative > .items-center'
if sb.is_element_visible(price_selector):
hotel_prices = sb.find_elements(price_selector)
elif sb.is_element_present(
'[font-size="12px"] + [font-size="20px"]'
):
hotel_prices = sb.find_elements(
'[font-size="12px"] + [font-size="20px"]'
)
else:
hotel_prices = sb.find_elements(
'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:
Expand All @@ -816,6 +828,8 @@ def test_presentation_4(self):
if hotel_prices[i] and hotel_prices[i].text:
count += 1
hotel_price = "$" + hotel_prices[i].text
if hotel_price.startswith("$$ "):
hotel_price = hotel_price.replace("$$ ", "$")
print("* %s: %s => %s" % (count, hotel.text, hotel_price))

self.create_presentation(theme="serif", transition="none")
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ exceptiongroup>=1.3.1
websockets~=15.0.1;python_version<"3.10"
websockets>=16.0;python_version>="3.10"
filelock~=3.19.1;python_version<"3.10"
filelock>=3.25.1;python_version>="3.10"
filelock>=3.25.2;python_version>="3.10"
fasteners>=0.20
mycdp>=1.3.3
mycdp>=1.3.4
pynose>=1.5.5
platformdirs~=4.4.0;python_version<"3.10"
platformdirs>=4.9.4;python_version>="3.10"
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.2"
__version__ = "4.47.3"
Loading