Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8d02cd

Browse files
authored
Merge pull request #3275 from seleniumbase/cdp-mode-patch-12
CDP Mode - Patch 12
2 parents 2339e8d + 74bacf2 commit d8d02cd

33 files changed

+345
-137
lines changed

‎.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
# Packages
55
*.egg
66
*.egg-info
7-
dist
8-
build
97
.eggs
108
eggs
11-
parts
12-
bin
13-
var
14-
sdist
159
develop-eggs
16-
.installed.cfg
10+
bin
11+
build
12+
dist
1713
lib
1814
lib64
15+
parts
16+
sdist
17+
var
18+
.installed.cfg
1919
__pycache__
2020

2121
# Python3 pyvenv

‎CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<h2><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32" /> CHANGELOG</h2>
22

3-
### See: [SeleniumBase/releases](https://github.com/seleniumbase/SeleniumBase/releases)
3+
## See: [SeleniumBase/releases](https://github.com/seleniumbase/SeleniumBase/releases) 🗂️ 📋
4+
5+
### (For CDP updates, see the [CDP Mode docs](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md))

‎examples/cdp_mode/ReadMe.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ To find out if WebDriver is connected or disconnected, call:
7171
```python
7272
from seleniumbase import SB
7373

74-
with SB(uc=True, test=True, locale_code="en") as sb:
74+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
7575
url = "https://www.pokemon.com/us"
7676
sb.activate_cdp_mode(url)
77-
sb.sleep(2.5)
78-
sb.cdp.click_if_visible("button#onetrust-reject-all-handler")
79-
sb.sleep(1.2)
80-
sb.cdp.click('a[href="https://www.pokemon.com/us/pokedex/"]')
77+
sb.sleep(3.2)
78+
sb.cdp.click("button#onetrust-accept-btn-handler")
8179
sb.sleep(1.2)
80+
sb.cdp.click("a span.icon_pokeball")
81+
sb.sleep(2.5)
8282
sb.cdp.click('b:contains("Show Advanced Search")')
83-
sb.sleep(1.2)
83+
sb.sleep(2.5)
8484
sb.cdp.click('span[data-type="type"][data-value="electric"]')
8585
sb.sleep(0.5)
8686
sb.scroll_into_view("a#advSearch")
8787
sb.sleep(0.5)
88-
sb.cdp.click("a#advSearch")
88+
sb.cdp.mouse_click("a#advSearch")
8989
sb.sleep(1.2)
9090
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
9191
sb.cdp.assert_text("Pikachu", 'div[class*="title"]')
@@ -102,11 +102,13 @@ with SB(uc=True, test=True, locale_code="en") as sb:
102102
sb.cdp.highlight_overlay("div.pokemon-ability-info")
103103
sb.sleep(2)
104104
sb.cdp.click('a[href="https://www.pokemon.com/us/play-pokemon/"]')
105+
sb.sleep(0.6)
105106
sb.cdp.click('h3:contains("Find an Event")')
106107
location = "Concord, MA, USA"
107108
sb.cdp.type('input[data-testid="location-search"]', location)
108-
sb.sleep(1)
109+
sb.sleep(1.5)
109110
sb.cdp.click("div.autocomplete-dropdown-container div.suggestion-item")
111+
sb.sleep(0.6)
110112
sb.cdp.click('img[alt="search-icon"]')
111113
sb.sleep(2)
112114
events = sb.cdp.select_all('div[data-testid="event-name"]')
@@ -129,10 +131,10 @@ with SB(uc=True, test=True, locale_code="en") as sb:
129131
```python
130132
from seleniumbase import SB
131133

132-
with SB(uc=True, test=True, locale_code="en") as sb:
134+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
133135
url = "https://www.hyatt.com/"
134136
sb.activate_cdp_mode(url)
135-
sb.sleep(2)
137+
sb.sleep(2.5)
136138
sb.cdp.click_if_visible('button[aria-label="Close"]')
137139
sb.sleep(1)
138140
sb.cdp.click('span:contains("Explore")')
@@ -176,7 +178,7 @@ with SB(uc=True, test=True, locale_code="en") as sb:
176178
```python
177179
from seleniumbase import SB
178180

179-
with SB(uc=True, test=True, locale_code="en") as sb:
181+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
180182
url = "https://www.bestwestern.com/en_US.html"
181183
sb.activate_cdp_mode(url)
182184
sb.sleep(2.5)
@@ -220,7 +222,7 @@ with SB(uc=True, test=True, locale_code="en") as sb:
220222
```python
221223
from seleniumbase import SB
222224

223-
with SB(uc=True, test=True, locale_code="en") as sb:
225+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
224226
url = "https://www.walmart.com/"
225227
sb.activate_cdp_mode(url)
226228
sb.sleep(2.5)
@@ -266,7 +268,7 @@ with SB(uc=True, test=True, locale_code="en") as sb:
266268
```python
267269
from seleniumbase import SB
268270

269-
with SB(uc=True, test=True, locale_code="en") as sb:
271+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
270272
url = "https://www.nike.com/"
271273
sb.activate_cdp_mode(url)
272274
sb.sleep(2.5)
@@ -395,12 +397,17 @@ sb.cdp.uncheck_if_checked(selector)
395397
sb.cdp.unselect_if_selected(selector)
396398
sb.cdp.is_element_present(selector)
397399
sb.cdp.is_element_visible(selector)
398-
sb.cdp.assert_element_present(selector)
399-
sb.cdp.assert_element_absent(selector)
400+
sb.cdp.wait_for_element_visible(selector)
400401
sb.cdp.assert_element(selector)
401402
sb.cdp.assert_element_visible(selector)
403+
sb.cdp.assert_element_present(selector)
404+
sb.cdp.assert_element_absent(selector)
402405
sb.cdp.assert_element_not_visible(selector)
406+
sb.cdp.assert_element_attribute(selector, attribute, value=None)
403407
sb.cdp.assert_title(title)
408+
sb.cdp.assert_title_contains(substring)
409+
sb.cdp.assert_url(url)
410+
sb.cdp.assert_url_contains(substring)
404411
sb.cdp.assert_text(text, selector="html")
405412
sb.cdp.assert_exact_text(text, selector="html")
406413
sb.cdp.scroll_into_view(selector)

‎examples/cdp_mode/raw_async.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def main():
3737
time.sleep(1)
3838
element = loop.run_until_complete(page.select("span.icon_pokeball"))
3939
loop.run_until_complete(element.click_async())
40-
time.sleep(1.5)
40+
time.sleep(2)
4141
print(loop.run_until_complete(page.evaluate("document.title")))
4242
time.sleep(1)
4343

@@ -46,17 +46,22 @@ async def main():
4646
sb = sb_cdp.CDPMethods(loop, page, driver)
4747
sb.set_locale("en")
4848
sb.open("https://www.priceline.com/")
49-
sb.sleep(3)
49+
sb.sleep(2.5)
5050
sb.internalize_links() # Don't open links in a new tab
5151
sb.click("#link_header_nav_experiences")
52-
sb.sleep(2.5)
52+
sb.sleep(3.5)
5353
sb.remove_elements("msm-cookie-banner")
5454
sb.sleep(1.5)
5555
location = "Amsterdam"
56-
sb.press_keys('input[data-test-id*="search"]', location)
56+
where_to = 'div[data-automation*="experiences"] input'
57+
button = 'button[data-automation*="experiences-search"]'
58+
sb.gui_click_element(where_to)
59+
sb.press_keys(where_to, location)
5760
sb.sleep(1)
58-
sb.click('input[data-test-id*="search"]')
59-
sb.sleep(2)
60-
sb.click('span[data-test-id*="autocomplete"]')
61-
sb.sleep(5)
61+
sb.gui_click_element(button)
62+
sb.sleep(3)
6263
print(sb.get_title())
64+
print("************")
65+
cards = sb.select_all('h2[data-automation*="product-list-card"]')
66+
for card in cards:
67+
print("* %s" % card.text)

‎examples/cdp_mode/raw_bestwestern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale_code="en") as sb:
3+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
44
url = "https://www.bestwestern.com/en_US.html"
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.5)

‎examples/cdp_mode/raw_cdp.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Example of using CDP Mode without WebDriver"""
22
import asyncio
3-
from contextlib import suppress
43
from seleniumbase import decorators
54
from seleniumbase.core import sb_cdp
65
from seleniumbase.undetected import cdp_driver
@@ -16,29 +15,28 @@ def main():
1615
sb = sb_cdp.CDPMethods(loop, page, driver)
1716
sb.set_locale("en") # This test expects English locale
1817
sb.open(url1)
19-
sb.sleep(3)
18+
sb.sleep(2.5)
2019
sb.internalize_links() # Don't open links in a new tab
2120
sb.click("#link_header_nav_experiences")
22-
sb.sleep(2.5)
21+
sb.sleep(3.5)
2322
sb.remove_elements("msm-cookie-banner")
2423
sb.sleep(1.5)
2524
location = "Amsterdam"
26-
sb.press_keys('input[data-test-id*="search"]', location)
25+
where_to = 'div[data-automation*="experiences"] input'
26+
button = 'button[data-automation*="experiences-search"]'
27+
sb.gui_click_element(where_to)
28+
sb.press_keys(where_to, location)
2729
sb.sleep(1)
28-
sb.click('input[data-test-id*="search"]')
29-
sb.sleep(2)
30-
sb.click('span[data-test-id*="autocomplete"]')
31-
sb.sleep(5)
30+
sb.gui_click_element(button)
31+
sb.sleep(3)
3232
print(sb.get_title())
33-
header = sb.get_text('h2[data-testid*="RelatedVenues"]')
34-
print("*** %s: ***" % header)
35-
cards = sb.select_all("div.venue-card__body")
33+
print("************")
34+
for i in range(8):
35+
sb.scroll_down(50)
36+
sb.sleep(0.2)
37+
cards = sb.select_all('h2[data-automation*="product-list-card"]')
3638
for card in cards:
37-
with suppress(Exception):
38-
venue = card.text.split("\n")[0].strip()
39-
rating = card.text.split("\n")[1].strip()
40-
reviews = card.text.split("\n")[2].strip()[1:-1]
41-
print("* %s: %s from %s reviews." % (venue, rating, reviews))
39+
print("* %s" % card.text)
4240

4341

4442
if __name__ == "__main__":

‎examples/cdp_mode/raw_cdp_with_sb.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Example of using CDP Mode with WebDriver"""
2-
from contextlib import suppress
32
from seleniumbase import SB
43

54

@@ -9,23 +8,22 @@
98
sb.sleep(2.5)
109
sb.internalize_links() # Don't open links in a new tab
1110
sb.click("#link_header_nav_experiences")
12-
sb.sleep(2.5)
11+
sb.sleep(3.5)
1312
sb.remove_elements("msm-cookie-banner")
1413
sb.sleep(1.5)
1514
location = "Amsterdam"
16-
sb.press_keys('input[data-test-id*="search"]', location)
15+
where_to = 'div[data-automation*="experiences"] input'
16+
button = 'button[data-automation*="experiences-search"]'
17+
sb.cdp.gui_click_element(where_to)
18+
sb.press_keys(where_to, location)
1719
sb.sleep(1)
18-
sb.click('input[data-test-id*="search"]')
19-
sb.sleep(2)
20-
sb.click('span[data-test-id*="autocomplete"]')
21-
sb.sleep(5)
20+
sb.cdp.gui_click_element(button)
21+
sb.sleep(3)
2222
print(sb.get_title())
23-
header = sb.get_text('h2[data-testid*="RelatedVenues"]')
24-
print("*** %s: ***" % header)
25-
cards = sb.select_all("div.venue-card__body")
23+
print("************")
24+
for i in range(8):
25+
sb.cdp.scroll_down(50)
26+
sb.sleep(0.2)
27+
cards = sb.select_all('h2[data-automation*="product-list-card"]')
2628
for card in cards:
27-
with suppress(Exception):
28-
venue = card.text.split("\n")[0].strip()
29-
rating = card.text.split("\n")[1].strip()
30-
reviews = card.text.split("\n")[2].strip()[1:-1]
31-
print("* %s: %s from %s reviews." % (venue, rating, reviews))
29+
print("* %s" % card.text)

‎examples/cdp_mode/raw_easyjet.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale_code="en") as sb:
3+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
44
url = "https://www.easyjet.com/en/"
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.5)
7-
sb.cdp.click_if_visible('button#ensRejectAll')
7+
sb.cdp.click_if_visible("button#ensCloseBanner")
88
sb.sleep(1.2)
99
sb.cdp.click('input[name="from"]')
1010
sb.sleep(1.2)
1111
sb.cdp.type('input[name="from"]', "London")
12-
sb.sleep(1.2)
12+
sb.sleep(0.6)
13+
sb.cdp.click_if_visible("button#ensCloseBanner")
14+
sb.sleep(0.6)
1315
sb.cdp.click('span[data-testid="airport-name"]')
1416
sb.sleep(1.2)
1517
sb.cdp.type('input[name="to"]', "Venice")
@@ -23,16 +25,20 @@
2325
sb.cdp.click('[data-testid="month"]:last-of-type [aria-disabled="false"]')
2426
sb.sleep(1.2)
2527
sb.cdp.click('button[data-testid="submit"]')
26-
sb.sleep(3.5)
28+
sb.sleep(2.5)
2729
sb.connect()
28-
sb.sleep(0.5)
29-
if "/buy/flights" 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")
30+
sb.sleep(1.2)
31+
for window in sb.driver.window_handles:
32+
sb.switch_to_window(window)
33+
if "/buy/flights" in sb.get_current_url():
34+
break
35+
sb.click_if_visible("button#ensCloseBanner")
36+
days = sb.find_elements('div[class*="FlightGridLayout_column"]')
3337
for day in days:
38+
if not day.text.strip():
39+
continue
3440
print("**** " + " ".join(day.text.split("\n")[0:2]) + " ****")
35-
fares = day.find_elements("css selector", "button.selectable")
41+
fares = day.find_elements("css selector", 'button[class*="flightDet"]')
3642
if not fares:
3743
print("No flights today!")
3844
for fare in fares:

‎examples/cdp_mode/raw_footlocker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale_code="en") as sb:
3+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
44
url = "https://www.footlocker.com/"
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.5)
77
sb.cdp.click_if_visible('button[id*="Agree"]')
8-
sb.sleep(1.5)
8+
sb.sleep(2.5)
99
sb.cdp.mouse_click('input[aria-label="Search"]')
10-
sb.sleep(1.5)
10+
sb.sleep(2.5)
1111
search = "Nike Shoes"
1212
sb.cdp.press_keys('input[aria-label="Search"]', search)
13-
sb.sleep(2)
13+
sb.sleep(2.5)
1414
sb.cdp.mouse_click('ul[id*="typeahead"] li div')
15-
sb.sleep(3)
15+
sb.sleep(3.5)
1616
elements = sb.cdp.select_all("a.ProductCard-link")
1717
if elements:
1818
print('**** Found results for "%s": ****' % search)

‎examples/cdp_mode/raw_hyatt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale_code="en") as sb:
3+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
44
url = "https://www.hyatt.com/"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(2)
6+
sb.sleep(2.5)
77
sb.cdp.click_if_visible('button[aria-label="Close"]')
88
sb.sleep(1)
99
sb.cdp.click('span:contains("Explore")')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /