From 04ec33510602c79078fb984792c5ff502de2712f Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 26 Feb 2025 17:31:52 -0500 Subject: [PATCH] Update CDP Mode examples --- examples/cdp_mode/ReadMe.md | 12 ++++++------ examples/cdp_mode/raw_ahrefs.py | 2 +- examples/cdp_mode/raw_albertsons.py | 2 +- examples/cdp_mode/raw_async.py | 20 ++++++++----------- examples/cdp_mode/raw_bestwestern.py | 2 +- examples/cdp_mode/raw_cdp.py | 14 +++---------- examples/cdp_mode/raw_cdp_extended.py | 23 ++++++++++++++++++++++ examples/cdp_mode/raw_cdp_methods.py | 10 ++-------- examples/cdp_mode/raw_cdp_nike.py | 13 +++---------- examples/cdp_mode/raw_cdp_with_sb.py | 2 +- examples/cdp_mode/raw_cf.py | 4 ++-- examples/cdp_mode/raw_easyjet.py | 2 +- examples/cdp_mode/raw_elal.py | 24 ++++++++++++----------- examples/cdp_mode/raw_footlocker.py | 2 +- examples/cdp_mode/raw_gettyimages.py | 2 +- examples/cdp_mode/raw_gitlab.py | 2 +- examples/cdp_mode/raw_hyatt.py | 2 +- examples/cdp_mode/raw_kohls.py | 2 +- examples/cdp_mode/raw_multi_async.py | 4 ++-- examples/cdp_mode/raw_multi_cdp.py | 9 ++------- examples/cdp_mode/raw_nike.py | 4 ++-- examples/cdp_mode/raw_nordstrom.py | 2 +- examples/cdp_mode/raw_pokemon.py | 2 +- examples/cdp_mode/raw_priceline.py | 2 +- examples/cdp_mode/raw_publication.py | 2 +- examples/cdp_mode/raw_radwell.py | 2 +- examples/cdp_mode/raw_req_async.py | 4 ++-- examples/cdp_mode/raw_req_mod.py | 2 +- examples/cdp_mode/raw_req_sb.py | 2 +- examples/cdp_mode/raw_res_nike.py | 4 ++-- examples/cdp_mode/raw_res_sb.py | 2 +- examples/cdp_mode/raw_southwest.py | 2 +- examples/cdp_mode/raw_theaters.py | 2 +- examples/cdp_mode/raw_united.py | 2 +- examples/cdp_mode/raw_wsform.py | 2 +- examples/cdp_mode/raw_xhr_async.py | 4 ++-- examples/cdp_mode/raw_xhr_sb.py | 2 +- examples/presenter/uc_presentation_3.py | 2 +- examples/presenter/uc_presentation_4.py | 26 ++++++++++++------------- examples/raw_ahrefs.py | 3 +-- examples/raw_cf.py | 4 ++-- 41 files changed, 112 insertions(+), 118 deletions(-) create mode 100644 examples/cdp_mode/raw_cdp_extended.py diff --git a/examples/cdp_mode/ReadMe.md b/examples/cdp_mode/ReadMe.md index 48d7c46e..0065d6b4 100644 --- a/examples/cdp_mode/ReadMe.md +++ b/examples/cdp_mode/ReadMe.md @@ -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) diff --git a/examples/cdp_mode/raw_ahrefs.py b/examples/cdp_mode/raw_ahrefs.py index 60f5554b..2d634361 100644 --- a/examples/cdp_mode/raw_ahrefs.py +++ b/examples/cdp_mode/raw_ahrefs.py @@ -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")' diff --git a/examples/cdp_mode/raw_albertsons.py b/examples/cdp_mode/raw_albertsons.py index 22e07820..0903054c 100644 --- a/examples/cdp_mode/raw_albertsons.py +++ b/examples/cdp_mode/raw_albertsons.py @@ -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) diff --git a/examples/cdp_mode/raw_async.py b/examples/cdp_mode/raw_async.py index 77874068..6ed65581 100644 --- a/examples/cdp_mode/raw_async.py +++ b/examples/cdp_mode/raw_async.py @@ -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") diff --git a/examples/cdp_mode/raw_bestwestern.py b/examples/cdp_mode/raw_bestwestern.py index 97031634..d22db30b 100644 --- a/examples/cdp_mode/raw_bestwestern.py +++ b/examples/cdp_mode/raw_bestwestern.py @@ -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) diff --git a/examples/cdp_mode/raw_cdp.py b/examples/cdp_mode/raw_cdp.py index c733859c..86c3daa4 100644 --- a/examples/cdp_mode/raw_cdp.py +++ b/examples/cdp_mode/raw_cdp.py @@ -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") diff --git a/examples/cdp_mode/raw_cdp_extended.py b/examples/cdp_mode/raw_cdp_extended.py new file mode 100644 index 00000000..ef3ec48a --- /dev/null +++ b/examples/cdp_mode/raw_cdp_extended.py @@ -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) diff --git a/examples/cdp_mode/raw_cdp_methods.py b/examples/cdp_mode/raw_cdp_methods.py index de69f956..4d5c0cdf 100644 --- a/examples/cdp_mode/raw_cdp_methods.py +++ b/examples/cdp_mode/raw_cdp_methods.py @@ -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") diff --git a/examples/cdp_mode/raw_cdp_nike.py b/examples/cdp_mode/raw_cdp_nike.py index 88c72539..e2b16298 100644 --- a/examples/cdp_mode/raw_cdp_nike.py +++ b/examples/cdp_mode/raw_cdp_nike.py @@ -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) diff --git a/examples/cdp_mode/raw_cdp_with_sb.py b/examples/cdp_mode/raw_cdp_with_sb.py index 14ce948d..d2f911f4 100644 --- a/examples/cdp_mode/raw_cdp_with_sb.py +++ b/examples/cdp_mode/raw_cdp_with_sb.py @@ -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) diff --git a/examples/cdp_mode/raw_cf.py b/examples/cdp_mode/raw_cf.py index af11c133..1d91373d 100644 --- a/examples/cdp_mode/raw_cf.py +++ b/examples/cdp_mode/raw_cf.py @@ -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) diff --git a/examples/cdp_mode/raw_easyjet.py b/examples/cdp_mode/raw_easyjet.py index 599277ff..32c73810 100644 --- a/examples/cdp_mode/raw_easyjet.py +++ b/examples/cdp_mode/raw_easyjet.py @@ -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) diff --git a/examples/cdp_mode/raw_elal.py b/examples/cdp_mode/raw_elal.py index 110b1e2b..81fe30cf 100644 --- a/examples/cdp_mode/raw_elal.py +++ b/examples/cdp_mode/raw_elal.py @@ -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: ***") diff --git a/examples/cdp_mode/raw_footlocker.py b/examples/cdp_mode/raw_footlocker.py index 311d9148..cd2672fd 100644 --- a/examples/cdp_mode/raw_footlocker.py +++ b/examples/cdp_mode/raw_footlocker.py @@ -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) diff --git a/examples/cdp_mode/raw_gettyimages.py b/examples/cdp_mode/raw_gettyimages.py index d2cf0a4f..875a1707 100644 --- a/examples/cdp_mode/raw_gettyimages.py +++ b/examples/cdp_mode/raw_gettyimages.py @@ -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") diff --git a/examples/cdp_mode/raw_gitlab.py b/examples/cdp_mode/raw_gitlab.py index 870c1f68..e13a4c44 100644 --- a/examples/cdp_mode/raw_gitlab.py +++ b/examples/cdp_mode/raw_gitlab.py @@ -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() diff --git a/examples/cdp_mode/raw_hyatt.py b/examples/cdp_mode/raw_hyatt.py index 5c92a222..12fc3945 100644 --- a/examples/cdp_mode/raw_hyatt.py +++ b/examples/cdp_mode/raw_hyatt.py @@ -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) diff --git a/examples/cdp_mode/raw_kohls.py b/examples/cdp_mode/raw_kohls.py index a29fa7ca..e6e1da0a 100644 --- a/examples/cdp_mode/raw_kohls.py +++ b/examples/cdp_mode/raw_kohls.py @@ -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) diff --git a/examples/cdp_mode/raw_multi_async.py b/examples/cdp_mode/raw_multi_async.py index cfbd64a2..afaf3238 100644 --- a/examples/cdp_mode/raw_multi_async.py +++ b/examples/cdp_mode/raw_multi_async.py @@ -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) diff --git a/examples/cdp_mode/raw_multi_cdp.py b/examples/cdp_mode/raw_multi_cdp.py index c7f42f4f..b814b44c 100644 --- a/examples/cdp_mode/raw_multi_cdp.py +++ b/examples/cdp_mode/raw_multi_cdp.py @@ -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") diff --git a/examples/cdp_mode/raw_nike.py b/examples/cdp_mode/raw_nike.py index 009f723d..7e28e2fc 100644 --- a/examples/cdp_mode/raw_nike.py +++ b/examples/cdp_mode/raw_nike.py @@ -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) diff --git a/examples/cdp_mode/raw_nordstrom.py b/examples/cdp_mode/raw_nordstrom.py index f2f0f3e6..ddc34dd1 100644 --- a/examples/cdp_mode/raw_nordstrom.py +++ b/examples/cdp_mode/raw_nordstrom.py @@ -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) diff --git a/examples/cdp_mode/raw_pokemon.py b/examples/cdp_mode/raw_pokemon.py index 4aecd0c1..f52d2f97 100644 --- a/examples/cdp_mode/raw_pokemon.py +++ b/examples/cdp_mode/raw_pokemon.py @@ -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) diff --git a/examples/cdp_mode/raw_priceline.py b/examples/cdp_mode/raw_priceline.py index bac86601..6142f9f0 100644 --- a/examples/cdp_mode/raw_priceline.py +++ b/examples/cdp_mode/raw_priceline.py @@ -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) diff --git a/examples/cdp_mode/raw_publication.py b/examples/cdp_mode/raw_publication.py index 77c8b546..a3d5fd73 100644 --- a/examples/cdp_mode/raw_publication.py +++ b/examples/cdp_mode/raw_publication.py @@ -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) diff --git a/examples/cdp_mode/raw_radwell.py b/examples/cdp_mode/raw_radwell.py index 34a674ce..305b21cf 100644 --- a/examples/cdp_mode/raw_radwell.py +++ b/examples/cdp_mode/raw_radwell.py @@ -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) diff --git a/examples/cdp_mode/raw_req_async.py b/examples/cdp_mode/raw_req_async.py index 7101ce6c..663c93d4 100644 --- a/examples/cdp_mode/raw_req_async.py +++ b/examples/cdp_mode/raw_req_async.py @@ -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" diff --git a/examples/cdp_mode/raw_req_mod.py b/examples/cdp_mode/raw_req_mod.py index eaa5f8d1..1609f1e0 100644 --- a/examples/cdp_mode/raw_req_mod.py +++ b/examples/cdp_mode/raw_req_mod.py @@ -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") diff --git a/examples/cdp_mode/raw_req_sb.py b/examples/cdp_mode/raw_req_sb.py index a547ab7a..96867257 100644 --- a/examples/cdp_mode/raw_req_sb.py +++ b/examples/cdp_mode/raw_req_sb.py @@ -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" diff --git a/examples/cdp_mode/raw_res_nike.py b/examples/cdp_mode/raw_res_nike.py index 459b143e..f4000c0e 100644 --- a/examples/cdp_mode/raw_res_nike.py +++ b/examples/cdp_mode/raw_res_nike.py @@ -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) diff --git a/examples/cdp_mode/raw_res_sb.py b/examples/cdp_mode/raw_res_sb.py index 1534ec20..7ea86cd0 100644 --- a/examples/cdp_mode/raw_res_sb.py +++ b/examples/cdp_mode/raw_res_sb.py @@ -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) diff --git a/examples/cdp_mode/raw_southwest.py b/examples/cdp_mode/raw_southwest.py index 0253b747..1f9fcc0a 100644 --- a/examples/cdp_mode/raw_southwest.py +++ b/examples/cdp_mode/raw_southwest.py @@ -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) diff --git a/examples/cdp_mode/raw_theaters.py b/examples/cdp_mode/raw_theaters.py index 442c9454..2481ed3f 100644 --- a/examples/cdp_mode/raw_theaters.py +++ b/examples/cdp_mode/raw_theaters.py @@ -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") diff --git a/examples/cdp_mode/raw_united.py b/examples/cdp_mode/raw_united.py index e819180c..cf39c8b1 100644 --- a/examples/cdp_mode/raw_united.py +++ b/examples/cdp_mode/raw_united.py @@ -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) diff --git a/examples/cdp_mode/raw_wsform.py b/examples/cdp_mode/raw_wsform.py index faee7c35..60586785 100644 --- a/examples/cdp_mode/raw_wsform.py +++ b/examples/cdp_mode/raw_wsform.py @@ -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") diff --git a/examples/cdp_mode/raw_xhr_async.py b/examples/cdp_mode/raw_xhr_async.py index 6f2f3c6e..ee548503 100644 --- a/examples/cdp_mode/raw_xhr_async.py +++ b/examples/cdp_mode/raw_xhr_async.py @@ -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) diff --git a/examples/cdp_mode/raw_xhr_sb.py b/examples/cdp_mode/raw_xhr_sb.py index 2475fe7f..81ff2782 100644 --- a/examples/cdp_mode/raw_xhr_sb.py +++ b/examples/cdp_mode/raw_xhr_sb.py @@ -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) diff --git a/examples/presenter/uc_presentation_3.py b/examples/presenter/uc_presentation_3.py index 3f6d6ca2..99815938 100644 --- a/examples/presenter/uc_presentation_3.py +++ b/examples/presenter/uc_presentation_3.py @@ -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")' diff --git a/examples/presenter/uc_presentation_4.py b/examples/presenter/uc_presentation_4.py index 42ff12b3..4732f2e7 100644 --- a/examples/presenter/uc_presentation_4.py +++ b/examples/presenter/uc_presentation_4.py @@ -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) diff --git a/examples/raw_ahrefs.py b/examples/raw_ahrefs.py index 3c8441cd..2849374c 100644 --- a/examples/raw_ahrefs.py +++ b/examples/raw_ahrefs.py @@ -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) diff --git a/examples/raw_cf.py b/examples/raw_cf.py index 58df9df8..e6152bc1 100644 --- a/examples/raw_cf.py +++ b/examples/raw_cf.py @@ -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)