Update CDP Mode examples

This commit is contained in:
Michael Mintz 2025-02-20 14:52:35 -05:00
parent 24317c15fb
commit 0949787a39
7 changed files with 26 additions and 11 deletions

View File

@ -328,11 +328,11 @@ with SB(uc=True, test=True, ad_block=True) as sb:
```python ```python
from seleniumbase import SB 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/" url = "https://www.nike.com/"
sb.activate_cdp_mode(url) sb.activate_cdp_mode(url)
sb.sleep(2.5) 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) sb.sleep(1.5)
search = "Nike Air Force 1" search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search) sb.cdp.press_keys('input[type="search"]', search)

View File

@ -8,7 +8,7 @@ driver = cdp_driver.cdp_util.start_sync()
page = loop.run_until_complete(driver.get(url)) page = loop.run_until_complete(driver.get(url))
sb = sb_cdp.CDPMethods(loop, page, driver) sb = sb_cdp.CDPMethods(loop, page, driver)
search = "Nike Fly Shoes" search = "Road Racing Shoes"
sb.click('div[data-testid="user-tools-container"]') sb.click('div[data-testid="user-tools-container"]')
sb.sleep(1) sb.sleep(1)
sb.press_keys('input[type="search"]', search) sb.press_keys('input[type="search"]', search)

View File

@ -5,9 +5,9 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
sb.activate_cdp_mode(url) sb.activate_cdp_mode(url)
sb.sleep(2.5) sb.sleep(2.5)
sb.cdp.click_if_visible('button[id*="Agree"]') 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.cdp.mouse_click('input[aria-label="Search"]')
sb.sleep(2.5) sb.sleep(1.5)
search = "Nike Shoes" search = "Nike Shoes"
sb.cdp.press_keys('input[aria-label="Search"]', search) sb.cdp.press_keys('input[aria-label="Search"]', search)
sb.sleep(2.5) sb.sleep(2.5)

View File

@ -1,10 +1,10 @@
from seleniumbase import SB 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/" url = "https://www.nike.com/"
sb.activate_cdp_mode(url) sb.activate_cdp_mode(url)
sb.sleep(2.5) 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) sb.sleep(1.5)
search = "Nike Air Force 1" search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search) sb.cdp.press_keys('input[type="search"]', search)

View File

@ -25,13 +25,13 @@ async def receive_handler(event: mycdp.network.ResponseReceived):
print(event.response) 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/" url = "https://www.nike.com/"
sb.activate_cdp_mode(url) sb.activate_cdp_mode(url)
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler) sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler) sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)
sb.sleep(2.5) 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) sb.sleep(1.5)
search = "Nike Air Force 1" search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search) sb.cdp.press_keys('input[type="search"]', search)

View File

@ -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))

View File

@ -838,11 +838,11 @@ class UCPresentationClass(BaseCase):
) )
self.begin_presentation(filename="uc_presentation.html") 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/" url = "https://www.nike.com/"
sb.activate_cdp_mode(url) sb.activate_cdp_mode(url)
sb.sleep(2.5) 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) sb.sleep(1.5)
search = "Nike Air Force 1" search = "Nike Air Force 1"
sb.cdp.press_keys('input[type="search"]', search) sb.cdp.press_keys('input[type="search"]', search)