-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3240 from seleniumbase/cdp-mode-patch-6
CDP Mode - Patch 6
- Loading branch information
Showing
15 changed files
with
460 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from seleniumbase import SB | ||
|
||
with SB(uc=True, test=True, locale_code="en") as sb: | ||
url = "https://www.easyjet.com/en/" | ||
sb.activate_cdp_mode(url) | ||
sb.sleep(2.5) | ||
sb.cdp.click_if_visible('button#ensRejectAll') | ||
sb.sleep(1.2) | ||
sb.cdp.click('input[name="from"]') | ||
sb.sleep(1.2) | ||
sb.cdp.type('input[name="from"]', "London") | ||
sb.sleep(1.2) | ||
sb.cdp.click('span[data-testid="airport-name"]') | ||
sb.sleep(1.2) | ||
sb.cdp.type('input[name="to"]', "Venice") | ||
sb.sleep(1.2) | ||
sb.cdp.click('span[data-testid="airport-name"]') | ||
sb.sleep(1.2) | ||
sb.cdp.click('input[name="when"]') | ||
sb.sleep(1.2) | ||
sb.cdp.click('[data-testid="month"] button[aria-disabled="false"]') | ||
sb.sleep(1.2) | ||
sb.cdp.click('[data-testid="month"]:last-of-type [aria-disabled="false"]') | ||
sb.sleep(1.2) | ||
sb.cdp.click('button[data-testid="submit"]') | ||
sb.sleep(3.5) | ||
sb.connect() | ||
sb.sleep(0.5) | ||
if "easyjet.com" not in sb.get_current_url(): | ||
sb.driver.close() | ||
sb.switch_to_newest_window() | ||
days = sb.find_elements("div.flight-grid-day") | ||
for day in days: | ||
print("**** " + " ".join(day.text.split("\n")[0:2]) + " ****") | ||
fares = day.find_elements("css selector", "button.selectable") | ||
if not fares: | ||
print("No flights today!") | ||
for fare in fares: | ||
info = fare.text | ||
info = info.replace("LOWEST FARE\n", "") | ||
info = info.replace("\n", " ") | ||
print(info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Using CDP.network.ResponseReceived and CDP.network.RequestWillBeSent.""" | ||
import colorama | ||
import mycdp | ||
import sys | ||
from seleniumbase import SB | ||
|
||
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX | ||
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX | ||
cr = colorama.Style.RESET_ALL | ||
if "linux" in sys.platform: | ||
c1 = c2 = cr = "" | ||
|
||
|
||
async def send_handler(event: mycdp.network.RequestWillBeSent): | ||
r = event.request | ||
s = f"{r.method} {r.url}" | ||
for k, v in r.headers.items(): | ||
s += f"\n\t{k} : {v}" | ||
print(c1 + "*** ==> RequestWillBeSent <== ***" + cr) | ||
print(s) | ||
|
||
|
||
async def receive_handler(event: mycdp.network.ResponseReceived): | ||
print(c2 + "*** ==> ResponseReceived <== ***" + cr) | ||
print(event.response) | ||
|
||
|
||
with SB(uc=True, test=True, locale_code="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) | ||
url = "https://seleniumbase.io/apps/calculator" | ||
sb.cdp.open(url) | ||
sb.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from seleniumbase import SB | ||
|
||
with SB(uc=True, test=True, locale_code="en") as sb: | ||
url = "https://www.walmart.com/" | ||
sb.activate_cdp_mode(url) | ||
sb.sleep(2.5) | ||
sb.cdp.mouse_click('input[aria-label="Search"]') | ||
sb.sleep(1.2) | ||
search = "Settlers of Catan Board Game" | ||
required_text = "Catan" | ||
sb.cdp.press_keys('input[aria-label="Search"]', search + "\n") | ||
sb.sleep(3.8) | ||
items = sb.cdp.find_elements('div[data-testid="list-view"]') | ||
print('*** Walmart Search for "%s":' % search) | ||
print(' (Results must contain "%s".)' % required_text) | ||
for item in items: | ||
if required_text in item.text: | ||
description = item.querySelector( | ||
'[data-automation-id="product-price"] + span' | ||
) | ||
if description: | ||
print("* " + description.text) | ||
price = item.querySelector( | ||
'[data-automation-id="product-price"]' | ||
) | ||
if price: | ||
price_text = price.text | ||
price_text = price_text.split("current price Now ")[-1] | ||
price_text = price_text.split("current price ")[-1] | ||
price_text = price_text.split(" ")[0] | ||
print(" (" + price_text + ")") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# seleniumbase package | ||
__version__ = "4.32.5" | ||
__version__ = "4.32.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.