From 0949787a392daf033beb4ecb3ce2ef86ae82deb0 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 20 Feb 2025 14:52:35 -0500 Subject: [PATCH] Update CDP Mode examples --- examples/cdp_mode/ReadMe.md | 4 ++-- examples/cdp_mode/raw_cdp_nike.py | 2 +- examples/cdp_mode/raw_footlocker.py | 4 ++-- examples/cdp_mode/raw_nike.py | 4 ++-- examples/cdp_mode/raw_res_nike.py | 4 ++-- examples/cdp_mode/raw_science.py | 15 +++++++++++++++ examples/presenter/uc_presentation_4.py | 4 ++-- 7 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 examples/cdp_mode/raw_science.py diff --git a/examples/cdp_mode/ReadMe.md b/examples/cdp_mode/ReadMe.md index 31d4bdea..2186fa90 100644 --- a/examples/cdp_mode/ReadMe.md +++ b/examples/cdp_mode/ReadMe.md @@ -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", ad_block=True) as sb: +with SB(uc=True, test=True, locale_code="en", pls="none") as sb: url = "https://www.nike.com/" sb.activate_cdp_mode(url) sb.sleep(2.5) - sb.cdp.gui_click_element('div[data-testid="user-tools-container"]') + sb.cdp.mouse_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_cdp_nike.py b/examples/cdp_mode/raw_cdp_nike.py index 48d83563..88c72539 100644 --- a/examples/cdp_mode/raw_cdp_nike.py +++ b/examples/cdp_mode/raw_cdp_nike.py @@ -8,7 +8,7 @@ driver = cdp_driver.cdp_util.start_sync() page = loop.run_until_complete(driver.get(url)) sb = sb_cdp.CDPMethods(loop, page, driver) -search = "Nike Fly Shoes" +search = "Road Racing Shoes" sb.click('div[data-testid="user-tools-container"]') sb.sleep(1) sb.press_keys('input[type="search"]', search) diff --git a/examples/cdp_mode/raw_footlocker.py b/examples/cdp_mode/raw_footlocker.py index 717a1e48..311d9148 100644 --- a/examples/cdp_mode/raw_footlocker.py +++ b/examples/cdp_mode/raw_footlocker.py @@ -5,9 +5,9 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb: sb.activate_cdp_mode(url) sb.sleep(2.5) sb.cdp.click_if_visible('button[id*="Agree"]') - sb.sleep(2.5) + sb.sleep(1.5) sb.cdp.mouse_click('input[aria-label="Search"]') - sb.sleep(2.5) + sb.sleep(1.5) search = "Nike Shoes" sb.cdp.press_keys('input[aria-label="Search"]', search) sb.sleep(2.5) diff --git a/examples/cdp_mode/raw_nike.py b/examples/cdp_mode/raw_nike.py index 3a811b0d..009f723d 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", ad_block=True) as sb: +with SB(uc=True, test=True, locale_code="en", pls="none") as sb: url = "https://www.nike.com/" sb.activate_cdp_mode(url) sb.sleep(2.5) - sb.cdp.gui_click_element('div[data-testid="user-tools-container"]') + sb.cdp.mouse_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_nike.py b/examples/cdp_mode/raw_res_nike.py index 416a001a..459b143e 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", ad_block=True) as sb: +with SB(uc=True, test=True, locale_code="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.gui_click_element('div[data-testid="user-tools-container"]') + sb.cdp.mouse_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_science.py b/examples/cdp_mode/raw_science.py new file mode 100644 index 00000000..792dca7c --- /dev/null +++ b/examples/cdp_mode/raw_science.py @@ -0,0 +1,15 @@ +from seleniumbase import SB + +with SB(uc=True, incognito=True, test=True) as sb: + url = "https://earth.esa.int/eogateway/search" + sb.activate_cdp_mode(url) + sb.sleep(1) + sb.cdp.click_if_visible('button:contains("Accept cookies")') + for i in range(20): + sb.cdp.scroll_to_bottom() + sb.cdp.click_if_visible('button:contains("READ MORE")') + sb.sleep(1) + elements = sb.cdp.find_elements("h4 a span") + for element in elements: + print(element.text) + print("*** Total entries: %s" % len(elements)) diff --git a/examples/presenter/uc_presentation_4.py b/examples/presenter/uc_presentation_4.py index dbba53da..42ff12b3 100644 --- a/examples/presenter/uc_presentation_4.py +++ b/examples/presenter/uc_presentation_4.py @@ -838,11 +838,11 @@ 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_code="en", pls="none") as sb: url = "https://www.nike.com/" sb.activate_cdp_mode(url) sb.sleep(2.5) - sb.cdp.gui_click_element('div[data-testid="user-tools-container"]') + sb.cdp.mouse_click('div[data-testid="user-tools-container"]') sb.sleep(1.5) search = "Nike Air Force 1" sb.cdp.press_keys('input[type="search"]', search)