Skip to content

Commit 57df468

Browse files
authored
Merge pull request #3240 from seleniumbase/cdp-mode-patch-6
CDP Mode - Patch 6
2 parents d0625e8 + ab3198a commit 57df468

File tree

15 files changed

+460
-15
lines changed

15 files changed

+460
-15
lines changed

examples/cdp_mode/ReadMe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ sb.cdp.find_all(selector)
231231
sb.cdp.find_elements_by_text(text, tag_name=None)
232232
sb.cdp.select(selector)
233233
sb.cdp.select_all(selector)
234+
sb.cdp.find_elements(selector)
234235
sb.cdp.click_link(link_text)
235236
sb.cdp.tile_windows(windows=None, max_columns=0)
236237
sb.cdp.get_all_cookies(*args, **kwargs)
@@ -290,13 +291,17 @@ sb.cdp.get_element_attributes(selector)
290291
sb.cdp.get_element_html(selector)
291292
sb.cdp.set_locale(locale)
292293
sb.cdp.set_attributes(selector, attribute, value)
294+
sb.cdp.gui_click_x_y(x, y)
295+
sb.cdp.gui_click_element(selector)
293296
sb.cdp.internalize_links()
294297
sb.cdp.is_element_present(selector)
295298
sb.cdp.is_element_visible(selector)
296299
sb.cdp.assert_element(selector)
297300
sb.cdp.assert_element_present(selector)
298301
sb.cdp.assert_text(text, selector="html")
299302
sb.cdp.assert_exact_text(text, selector="html")
303+
sb.cdp.scroll_down(amount=25)
304+
sb.cdp.scroll_up(amount=25)
300305
sb.cdp.save_screenshot(name, folder=None, selector=None)
301306
```
302307

examples/cdp_mode/raw_easyjet.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, locale_code="en") as sb:
4+
url = "https://www.easyjet.com/en/"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(2.5)
7+
sb.cdp.click_if_visible('button#ensRejectAll')
8+
sb.sleep(1.2)
9+
sb.cdp.click('input[name="from"]')
10+
sb.sleep(1.2)
11+
sb.cdp.type('input[name="from"]', "London")
12+
sb.sleep(1.2)
13+
sb.cdp.click('span[data-testid="airport-name"]')
14+
sb.sleep(1.2)
15+
sb.cdp.type('input[name="to"]', "Venice")
16+
sb.sleep(1.2)
17+
sb.cdp.click('span[data-testid="airport-name"]')
18+
sb.sleep(1.2)
19+
sb.cdp.click('input[name="when"]')
20+
sb.sleep(1.2)
21+
sb.cdp.click('[data-testid="month"] button[aria-disabled="false"]')
22+
sb.sleep(1.2)
23+
sb.cdp.click('[data-testid="month"]:last-of-type [aria-disabled="false"]')
24+
sb.sleep(1.2)
25+
sb.cdp.click('button[data-testid="submit"]')
26+
sb.sleep(3.5)
27+
sb.connect()
28+
sb.sleep(0.5)
29+
if "easyjet.com" not in sb.get_current_url():
30+
sb.driver.close()
31+
sb.switch_to_newest_window()
32+
days = sb.find_elements("div.flight-grid-day")
33+
for day in days:
34+
print("**** " + " ".join(day.text.split("\n")[0:2]) + " ****")
35+
fares = day.find_elements("css selector", "button.selectable")
36+
if not fares:
37+
print("No flights today!")
38+
for fare in fares:
39+
info = fare.text
40+
info = info.replace("LOWEST FARE\n", "")
41+
info = info.replace("\n", " ")
42+
print(info)

examples/cdp_mode/raw_req_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Using CDP.fetch.RequestPaused to filter content in real time."""
1+
"""Using CDP.fetch.RequestPaused to filter content in real-time."""
22
import asyncio
33
import mycdp
44
from seleniumbase import decorators

examples/cdp_mode/raw_req_sb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Using CDP.fetch.RequestPaused to filter content in real time."""
1+
"""Using CDP.fetch.RequestPaused to filter content in real-time."""
22
import mycdp
33
from seleniumbase import SB
44

examples/cdp_mode/raw_res_sb.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Using CDP.network.ResponseReceived and CDP.network.RequestWillBeSent."""
2+
import colorama
3+
import mycdp
4+
import sys
5+
from seleniumbase import SB
6+
7+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
8+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
9+
cr = colorama.Style.RESET_ALL
10+
if "linux" in sys.platform:
11+
c1 = c2 = cr = ""
12+
13+
14+
async def send_handler(event: mycdp.network.RequestWillBeSent):
15+
r = event.request
16+
s = f"{r.method} {r.url}"
17+
for k, v in r.headers.items():
18+
s += f"\n\t{k} : {v}"
19+
print(c1 + "*** ==> RequestWillBeSent <== ***" + cr)
20+
print(s)
21+
22+
23+
async def receive_handler(event: mycdp.network.ResponseReceived):
24+
print(c2 + "*** ==> ResponseReceived <== ***" + cr)
25+
print(event.response)
26+
27+
28+
with SB(uc=True, test=True, locale_code="en") as sb:
29+
sb.activate_cdp_mode("about:blank")
30+
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
31+
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)
32+
url = "https://seleniumbase.io/apps/calculator"
33+
sb.cdp.open(url)
34+
sb.sleep(1)

examples/cdp_mode/raw_walmart.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, locale_code="en") as sb:
4+
url = "https://www.walmart.com/"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(2.5)
7+
sb.cdp.mouse_click('input[aria-label="Search"]')
8+
sb.sleep(1.2)
9+
search = "Settlers of Catan Board Game"
10+
required_text = "Catan"
11+
sb.cdp.press_keys('input[aria-label="Search"]', search + "\n")
12+
sb.sleep(3.8)
13+
items = sb.cdp.find_elements('div[data-testid="list-view"]')
14+
print('*** Walmart Search for "%s":' % search)
15+
print(' (Results must contain "%s".)' % required_text)
16+
for item in items:
17+
if required_text in item.text:
18+
description = item.querySelector(
19+
'[data-automation-id="product-price"] + span'
20+
)
21+
if description:
22+
print("* " + description.text)
23+
price = item.querySelector(
24+
'[data-automation-id="product-price"]'
25+
)
26+
if price:
27+
price_text = price.text
28+
price_text = price_text.split("current price Now ")[-1]
29+
price_text = price_text.split("current price ")[-1]
30+
price_text = price_text.split(" ")[0]
31+
print(" (" + price_text + ")")

examples/raw_pixelscan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
with SB(uc=True, incognito=True, test=True) as sb:
44
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 10)
5+
sb.remove_elements("div.banner") # Remove the banner
56
sb.remove_elements("jdiv") # Remove chat widgets
67
no_automation_detected = "No automation framework detected"
78
sb.assert_text(no_automation_detected, "pxlscn-bot-detection")

help_docs/customizing_test_runs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pytest test_suite.py
238238

239239
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Demo Mode:</h3>
240240

241-
🔵 If any test is moving too fast for your eyes to see what's going on, you can run it in **Demo Mode** by adding ``--demo`` on the command line, which pauses the browser briefly between actions, highlights page elements being acted on, and lets you know what test assertions are happening in real time:
241+
🔵 If any test is moving too fast for your eyes to see what's going on, you can run it in **Demo Mode** by adding ``--demo`` on the command line, which pauses the browser briefly between actions, highlights page elements being acted on, and lets you know what test assertions are happening in real-time:
242242

243243
```bash
244244
pytest my_first_test.py --demo
@@ -335,7 +335,7 @@ class Test:
335335
pytest --headless -n8 --dashboard --html=report.html -v --rs --crumbs
336336
```
337337

338-
The above not only runs tests in parallel processes, but it also tells tests in the same process to share the same browser session, runs the tests in headless mode, displays the full name of each test on a separate line, creates a realtime dashboard of the test results, and creates a full report after all tests complete.
338+
The above not only runs tests in parallel processes, but it also tells tests in the same process to share the same browser session, runs the tests in headless mode, displays the full name of each test on a separate line, creates a real-time dashboard of the test results, and creates a full report after all tests complete.
339339

340340
--------
341341

mkdocs_build/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# mkdocs dependencies for generating the seleniumbase.io website
2-
# Minimum Python version: 3.8 (for generating docs only)
2+
# Minimum Python version: 3.9 (for generating docs only)
33

44
regex>=2024.9.11
5-
pymdown-extensions>=10.11.2
5+
pymdown-extensions>=10.12
66
pipdeptree>=2.23.4
77
python-dateutil>=2.8.2
88
Markdown==3.7
@@ -11,7 +11,7 @@ MarkupSafe==3.0.2
1111
Jinja2==3.1.4
1212
click==8.1.7
1313
ghp-import==2.1.0
14-
watchdog==5.0.3
14+
watchdog==6.0.0
1515
cairocffi==1.7.1
1616
pathspec==0.12.1
1717
Babel==2.16.0
@@ -20,7 +20,7 @@ lxml==5.3.0
2020
pyquery==2.0.1
2121
readtime==3.0.0
2222
mkdocs==1.6.1
23-
mkdocs-material==9.5.42
23+
mkdocs-material==9.5.43
2424
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trio==0.27.0
3636
trio-websocket==0.11.1
3737
wsproto==1.2.0
3838
websocket-client==1.8.0
39-
selenium==4.25.0
39+
selenium==4.26.1
4040
cssselect==1.2.0
4141
sortedcontainers==2.4.0
4242
execnet==2.1.1
@@ -64,7 +64,8 @@ rich==13.9.3
6464

6565
coverage>=7.6.1;python_version<"3.9"
6666
coverage>=7.6.4;python_version>="3.9"
67-
pytest-cov>=5.0.0
67+
pytest-cov>=5.0.0;python_version<"3.9"
68+
pytest-cov>=6.0.0;python_version>="3.9"
6869
flake8==5.0.4;python_version<"3.9"
6970
flake8==7.1.1;python_version>="3.9"
7071
mccabe==0.7.0

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.32.5"
2+
__version__ = "4.32.6"

seleniumbase/core/browser_launcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def uc_open_with_cdp_mode(driver, url=None):
588588
cdp.find_elements_by_text = CDPM.find_elements_by_text
589589
cdp.select = CDPM.select
590590
cdp.select_all = CDPM.select_all
591+
cdp.find_elements = CDPM.find_elements
591592
cdp.click_link = CDPM.click_link
592593
cdp.tile_windows = CDPM.tile_windows
593594
cdp.get_all_cookies = CDPM.get_all_cookies
@@ -619,6 +620,8 @@ def uc_open_with_cdp_mode(driver, url=None):
619620
cdp.reset_window_size = CDPM.reset_window_size
620621
cdp.set_locale = CDPM.set_locale
621622
cdp.set_attributes = CDPM.set_attributes
623+
cdp.gui_click_x_y = CDPM.gui_click_x_y
624+
cdp.gui_click_element = CDPM.gui_click_element
622625
cdp.internalize_links = CDPM.internalize_links
623626
cdp.get_window = CDPM.get_window
624627
cdp.get_element_attributes = CDPM.get_element_attributes
@@ -655,6 +658,8 @@ def uc_open_with_cdp_mode(driver, url=None):
655658
cdp.assert_element_visible = CDPM.assert_element
656659
cdp.assert_text = CDPM.assert_text
657660
cdp.assert_exact_text = CDPM.assert_exact_text
661+
cdp.scroll_down = CDPM.scroll_down
662+
cdp.scroll_up = CDPM.scroll_up
658663
cdp.save_screenshot = CDPM.save_screenshot
659664
cdp.page = page # async world
660665
cdp.driver = driver.cdp_base # async world
@@ -2218,7 +2223,6 @@ def _set_chrome_options(
22182223
)
22192224
):
22202225
chrome_options.add_argument("--no-pings")
2221-
chrome_options.add_argument("--disable-popup-blocking")
22222226
chrome_options.add_argument("--homepage=chrome://version/")
22232227
chrome_options.add_argument("--animation-duration-scale=0")
22242228
chrome_options.add_argument("--wm-window-animations-disabled")

0 commit comments

Comments
 (0)