Update CDP Mode examples

This commit is contained in:
Michael Mintz 2025-02-26 17:31:52 -05:00
parent 9beb99fa0e
commit 04ec335106
41 changed files with 112 additions and 118 deletions

View File

@ -50,7 +50,7 @@ Simple example: ([SeleniumBase/examples/cdp_mode/raw_gitlab.py](https://github.c
```python
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://gitlab.com/users/sign_in"
sb.activate_cdp_mode(url)
sb.uc_gui_click_captcha()
@ -130,7 +130,7 @@ To find out if WebDriver is connected or disconnected, call:
```python
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.2)
@ -189,7 +189,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
```python
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -236,7 +236,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
```python
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -328,11 +328,11 @@ with SB(uc=True, test=True, ad_block=True) as sb:
```python
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
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.mouse_click('div[data-testid="user-tools-container"]')
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, incognito=True, locale_code="en") as sb:
with SB(uc=True, test=True, incognito=True, locale="en") as sb:
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.albertsons.com/recipes/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,15 +1,14 @@
import asyncio
import time
from contextlib import suppress
from seleniumbase.core import sb_cdp
from seleniumbase.undetected import cdp_driver
from seleniumbase import sb_cdp
from seleniumbase import cdp_driver
async def main():
driver = await cdp_driver.cdp_util.start_async()
page = await driver.get("about:blank")
await page.set_locale("en")
await page.get("https://www.priceline.com/")
url = "https://www.priceline.com/"
driver = await cdp_driver.start_async(lang="en")
page = await driver.get(url)
time.sleep(3)
print(await page.evaluate("document.title"))
element = await page.select('[data-testid*="endLocation"]')
@ -24,7 +23,7 @@ if __name__ == "__main__":
loop.run_until_complete(main())
# Call everything without using async / await
driver = cdp_driver.cdp_util.start_sync()
driver = cdp_driver.start_sync()
page = loop.run_until_complete(driver.get("about:blank"))
loop.run_until_complete(page.set_locale("en"))
loop.run_until_complete(page.get("https://www.pokemon.com/us"))
@ -41,11 +40,8 @@ if __name__ == "__main__":
print(loop.run_until_complete(page.evaluate("document.title")))
time.sleep(1)
# Call CDP methods via the simplified CDP API
page = loop.run_until_complete(driver.get("about:blank"))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb.set_locale("en")
sb.open("https://www.priceline.com/")
# Call CDP methods via the simplified SB CDP API
sb = sb_cdp.Chrome("https://www.priceline.com/")
sb.sleep(2.5)
sb.internalize_links() # Don't open links in a new tab
sb.click("#link_header_nav_experiences")

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,20 +1,12 @@
"""Example of using CDP Mode without WebDriver"""
import asyncio
from seleniumbase import decorators
from seleniumbase.core import sb_cdp
from seleniumbase.undetected import cdp_driver
from seleniumbase import sb_cdp
@decorators.print_runtime("CDP Priceline Example")
def main():
url0 = "about:blank" # Set Locale code from here first
url1 = "https://www.priceline.com/" # (The "real" URL)
loop = asyncio.new_event_loop()
driver = cdp_driver.cdp_util.start_sync()
page = loop.run_until_complete(driver.get(url0))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb.set_locale("en") # This test expects English locale
sb.open(url1)
url = "https://www.priceline.com/"
sb = sb_cdp.Chrome(url, lang="en")
sb.sleep(2.5)
sb.internalize_links() # Don't open links in a new tab
sb.click("#link_header_nav_experiences")

View File

@ -0,0 +1,23 @@
"""The long way of using CDP Mode without WebDriver"""
import asyncio
from seleniumbase import sb_cdp
from seleniumbase import cdp_driver
url = "https://seleniumbase.io/demo_page"
loop = asyncio.new_event_loop()
driver = cdp_driver.start_sync()
page = loop.run_until_complete(driver.get(url))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb.press_keys("input", "Text")
sb.highlight("button")
sb.type("textarea", "Here are some words")
sb.click("button")
sb.set_value("input#mySlider", "100")
sb.click_visible_elements("input.checkBoxClassB")
sb.select_option_by_text("#mySelect", "Set to 75%")
sb.gui_hover_and_click("#myDropdown", "#dropOption2")
sb.gui_click_element("#checkBox1")
sb.gui_drag_and_drop("img#logo", "div#drop2")
sb.nested_click("iframe#myFrame3", ".fBox")
sb.sleep(2)

View File

@ -1,13 +1,7 @@
import asyncio
from seleniumbase.core import sb_cdp
from seleniumbase.undetected import cdp_driver
from seleniumbase import sb_cdp
url = "https://seleniumbase.io/demo_page"
loop = asyncio.new_event_loop()
driver = cdp_driver.cdp_util.start_sync()
page = loop.run_until_complete(driver.get(url))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb = sb_cdp.Chrome(url)
sb.press_keys("input", "Text")
sb.highlight("button")
sb.type("textarea", "Here are some words")

View File

@ -1,19 +1,12 @@
import asyncio
from seleniumbase.core import sb_cdp
from seleniumbase.undetected import cdp_driver
from seleniumbase import sb_cdp
url = "https://www.nike.com/"
loop = asyncio.new_event_loop()
driver = cdp_driver.cdp_util.start_sync()
page = loop.run_until_complete(driver.get(url))
sb = sb_cdp.CDPMethods(loop, page, driver)
search = "Road Racing Shoes"
sb = sb_cdp.Chrome(url)
sb.click('div[data-testid="user-tools-container"]')
sb.sleep(1)
search = "Road Racing Shoes"
sb.press_keys('input[type="search"]', search)
sb.sleep(4)
elements = sb.select_all('ul[data-testid*="products"] figure .details')
if elements:
print('**** Found results for "%s": ****' % search)

View File

@ -2,7 +2,7 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.priceline.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,14 +1,14 @@
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", guest=True) as sb:
with SB(uc=True, test=True, locale="en", 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.sleep(2)
with SB(uc=True, test=True, locale_code="en", guest=True) as sb:
with SB(uc=True, test=True, locale="en", guest=True) as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(3)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.easyjet.com/en/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "www.elal.com/flight-deals/en-us/flights-from-boston-to-tel-aviv"
sb.activate_cdp_mode(url)
sb.sleep(2)
@ -36,19 +36,21 @@ with SB(uc=True, test=True, locale_code="en") as sb:
sb.cdp.click(search_cell)
sb.sleep(5)
else:
elements = sb.cdp.find_elements("div.ui-bound__price__value")
print("*** Lowest Prices: ***")
first = True
departure_prices = "#uiFlightPanel0 div.ui-bound__price__value"
return_prices = "#uiFlightPanel1 div.ui-bound__price__value"
elements = sb.cdp.find_elements(departure_prices)
for element in elements:
if "lowest price" in element.text:
if first:
print("Departure Flight:")
print(element.text)
first = False
else:
print("Return Flight:")
print(element.text)
break
print("Departure Flight:")
print(element.text)
break
elements = sb.cdp.find_elements(return_prices)
for element in elements:
if "lowest price" in element.text:
print("Return Flight:")
print(element.text)
break
dates = sb.cdp.find_elements('div[class*="flight-date"]')
if len(dates) == 2:
print("*** Departure Date: ***")

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.footlocker.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
with SB(uc=True, test=True, locale="en", pls="none") as sb:
sb.activate_cdp_mode("https://www.gettyimages.com/")
sb.cdp.click('label:contains("Editorial")')
sb.cdp.press_keys("form input", "comic con 2024 sci fi panel\n")

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://gitlab.com/users/sign_in"
sb.activate_cdp_mode(url)
sb.uc_gui_click_captcha()

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.kohls.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)

View File

@ -2,11 +2,11 @@
import asyncio
from concurrent.futures import ThreadPoolExecutor
from random import randint
from seleniumbase.undetected import cdp_driver
from seleniumbase import cdp_driver
async def main(url):
driver = await cdp_driver.cdp_util.start_async()
driver = await cdp_driver.start_async()
page = await driver.get(url)
await page.set_window_rect(randint(4, 600), randint(8, 410), 860, 500)
await page.sleep(0.5)

View File

@ -1,16 +1,11 @@
# Testing multiple CDP drivers using the sync API
import asyncio
from concurrent.futures import ThreadPoolExecutor
from random import randint
from seleniumbase.core import sb_cdp
from seleniumbase.undetected import cdp_driver
from seleniumbase import sb_cdp
def main(url):
loop = asyncio.new_event_loop()
driver = cdp_driver.cdp_util.start_sync()
page = loop.run_until_complete(driver.get(url))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb = sb_cdp.Chrome(url)
sb.set_window_rect(randint(4, 720), randint(8, 410), 800, 500)
sb.press_keys("input", "Text")
sb.highlight("button")

View File

@ -1,10 +1,10 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
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.mouse_click('div[data-testid="user-tools-container"]')
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.nordstrom.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.2)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.2)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
window_handle = sb.driver.current_window_handle
url = "https://www.priceline.com"
sb.activate_cdp_mode(url)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.researchgate.net/search/publication"
sb.activate_cdp_mode(url)
sb.sleep(2)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
with SB(uc=True, test=True, locale="en", incognito=True) as sb:
url = "https://www.radwell.com/en-US/Search/Advanced/"
sb.activate_cdp_mode(url)
sb.sleep(3)

View File

@ -4,7 +4,7 @@ import colorama
import mycdp
import sys
from seleniumbase import decorators
from seleniumbase.undetected import cdp_driver
from seleniumbase import cdp_driver
c1 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
@ -30,7 +30,7 @@ class RequestPausedTest():
)
async def start_test(self):
driver = await cdp_driver.cdp_util.start_async()
driver = await cdp_driver.start_async()
tab = await driver.get("about:blank")
tab.add_handler(mycdp.fetch.RequestPaused, self.request_paused_handler)
url = "https://gettyimages.com/photos/firefly-2003-nathan"

View File

@ -14,7 +14,7 @@ async def request_paused_handler(event, tab):
tab.feed_cdp(mycdp.fetch.continue_request(request_id=rid, url=new_url))
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
with SB(uc=True, test=True, locale="en", pls="none") as sb:
sb.activate_cdp_mode("about:blank")
sb.cdp.add_handler(mycdp.fetch.RequestPaused, request_paused_handler)
sb.cdp.open("https://gettyimages.com/photos/jonathan-frakes-cast-2022")

View File

@ -23,7 +23,7 @@ async def request_paused_handler(event, tab):
tab.feed_cdp(mycdp.fetch.fail_request(event.request_id, TIMED_OUT))
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
sb.activate_cdp_mode("about:blank")
sb.cdp.add_handler(mycdp.fetch.RequestPaused, request_paused_handler)
url = "https://gettyimages.com/photos/firefly-2003-nathan"

View File

@ -25,13 +25,13 @@ async def receive_handler(event: mycdp.network.ResponseReceived):
print(event.response)
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
with SB(uc=True, test=True, locale="en", pls="none") as sb:
url = "https://www.nike.com/"
sb.activate_cdp_mode(url)
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)
sb.sleep(2.5)
sb.cdp.mouse_click('div[data-testid="user-tools-container"]')
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)

View File

@ -25,7 +25,7 @@ async def receive_handler(event: mycdp.network.ResponseReceived):
print(event.response)
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
sb.activate_cdp_mode("about:blank")
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.southwest.com/air/booking/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)

View File

@ -1,7 +1,7 @@
"""Simple web-scraping example in CDP Mode"""
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://architectureofcities.com/roman-theaters"
sb.activate_cdp_mode(url)
sb.cdp.click_if_visible("#cn-close-notice")

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
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.5)

View File

@ -1,6 +1,6 @@
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
with SB(uc=True, test=True, locale="en", incognito=True) as sb:
url = "https://wsform.com/demo/"
sb.activate_cdp_mode(url)
sb.scroll_into_view("div.grid")

View File

@ -5,7 +5,7 @@ import colorama
import mycdp
import sys
import time
from seleniumbase.undetected import cdp_driver
from seleniumbase import cdp_driver
xhr_requests = []
last_xhr_request = None
@ -58,7 +58,7 @@ async def receiveXHR(page, requests):
async def crawl():
driver = await cdp_driver.cdp_util.start_async()
driver = await cdp_driver.start_async()
tab = await driver.get("about:blank")
listenXHR(tab)

View File

@ -56,7 +56,7 @@ async def receiveXHR(page, requests):
return responses
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
sb.activate_cdp_mode("about:blank")
tab = sb.cdp.page
listenXHR(tab)

View File

@ -273,7 +273,7 @@ class UCPresentationClass(BaseCase):
self.begin_presentation(filename="uc_presentation.html")
with suppress(Exception):
with SB(uc=True, incognito=True, locale_code="en") as sb:
with SB(uc=True, incognito=True, locale="en") as sb:
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'

View File

@ -352,7 +352,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "www.planetminecraft.com/account/sign_in/"
sb.activate_cdp_mode(url)
sb.sleep(2)
@ -367,7 +367,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(3)
@ -382,7 +382,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://gitlab.com/users/sign_in"
sb.activate_cdp_mode(url)
sb.sleep(2)
@ -433,7 +433,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.bing.com/turing/captcha/challenge"
sb.activate_cdp_mode(url)
sb.sleep(1)
@ -458,7 +458,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.2)
@ -565,7 +565,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.albertsons.com/recipes/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -611,7 +611,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.easyjet.com/en/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -678,7 +678,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -727,7 +727,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
@ -769,7 +769,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
window_handle = sb.driver.current_window_handle
url = "https://www.priceline.com"
sb.activate_cdp_mode(url)
@ -838,11 +838,11 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", pls="none") as sb:
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.mouse_click('div[data-testid="user-tools-container"]')
sb.cdp.click('div[data-testid="user-tools-container"]')
sb.sleep(1.5)
search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search)
@ -866,7 +866,7 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.nordstrom.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.2)

View File

@ -1,12 +1,11 @@
from seleniumbase import SB
with SB(uc=True, test=True, incognito=True, locale_code="en") as sb:
with SB(uc=True, test=True, incognito=True, locale="en") as sb:
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'
sb.uc_open_with_reconnect(url) # The bot-check is later
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
sb.reconnect(0.1)
sb.uc_click(submit_button, reconnect_time=3.25)
sb.uc_gui_click_captcha()
sb.wait_for_text_not_visible("Checking", timeout=15)

View File

@ -1,13 +1,13 @@
"""SB Manager using UC Mode & PyAutoGUI for bypassing CAPTCHAs."""
from seleniumbase import SB
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.cloudflare.com/login"
sb.uc_open_with_reconnect(url, 5.5)
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
sb.sleep(2.5)
with SB(uc=True, test=True, locale_code="en") as sb:
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.cloudflare.com/login"
sb.uc_open_with_reconnect(url, 5.5)
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)