Skip to content

Commit 3e3aa69

Browse files
authored
Merge pull request #4212 from seleniumbase/update-cdp-and-selenium
Update CDP and Selenium
2 parents 6bbca0f + 0882ac8 commit 3e3aa69

File tree

13 files changed

+189
-33
lines changed

13 files changed

+189
-33
lines changed

examples/cdp_mode/ReadMe.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ await tab.get_current_url()
692692
await tab.send_keys(selector, text, timeout=5)
693693
await tab.type(selector, text, timeout=5)
694694
await tab.click(selector, timeout=5)
695+
await tab.click_if_visible(selector, timeout=0)
695696
await tab.click_with_offset(selector, x, y, center=False, timeout=5)
696697
await tab.solve_captcha()
697698
await tab.click_captcha() # Same as solve_captcha()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import asyncio
2+
from playwright.async_api import async_playwright
3+
from seleniumbase import cdp_driver
4+
5+
6+
async def main():
7+
driver = await cdp_driver.start_async()
8+
endpoint_url = driver.get_endpoint_url()
9+
tab = await driver.get("about:blank")
10+
11+
async with async_playwright() as p:
12+
browser = await p.chromium.connect_over_cdp(endpoint_url)
13+
context = browser.contexts[0]
14+
page = context.pages[0]
15+
url = (
16+
"https://www.gassaferegister.co.uk/gas-safety"
17+
"/gas-safety-certificates-records/building-regulations-certificate"
18+
"/order-replacement-building-regulations-certificate/"
19+
)
20+
await page.goto(url)
21+
await tab.sleep(0.6)
22+
await tab.solve_captcha()
23+
await page.wait_for_selector("#SearchTerm")
24+
await tab.sleep(1.4)
25+
allow_cookies = 'button:contains("Allow all cookies")'
26+
await tab.click_if_visible(allow_cookies, timeout=2)
27+
await tab.sleep(1)
28+
await page.fill("#SearchTerm", "Hydrogen")
29+
await page.click("button.search-button")
30+
await tab.sleep(3)
31+
results = await tab.query_selector_all("div.search-result")
32+
for result in results:
33+
print(result.text.replace(" " * 12, " ").strip() + "\n")
34+
await tab.scroll_down(50)
35+
await tab.sleep(1)
36+
37+
38+
if __name__ == "__main__":
39+
loop = asyncio.new_event_loop()
40+
loop.run_until_complete(main())

examples/cdp_mode/playwright/raw_gas_info_sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
"/order-replacement-building-regulations-certificate/"
1515
)
1616
page.goto(url)
17-
sb.sleep(0.5)
17+
sb.sleep(0.6)
1818
sb.solve_captcha()
1919
page.wait_for_selector("#SearchTerm")
20+
sb.sleep(1.4)
2021
allow_cookies = 'button:contains("Allow all cookies")'
2122
sb.click_if_visible(allow_cookies, timeout=2)
2223
sb.sleep(1)

examples/cdp_mode/raw_gas_records.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"/order-replacement-building-regulations-certificate/"
99
)
1010
sb.activate_cdp_mode(url)
11-
sb.sleep(0.5)
11+
sb.sleep(0.6)
1212
sb.solve_captcha()
1313
sb.wait_for_element("#SearchTerm", timeout=5)
14-
sb.sleep(2)
14+
sb.sleep(1.4)
1515
allow_cookies = 'button:contains("Allow all cookies")'
1616
sb.click_if_visible(allow_cookies, timeout=2)
1717
sb.sleep(1)

examples/cdp_mode/raw_kohls.py

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

33
with SB(uc=True, test=True, locale="en", incognito=True) as sb:
44
url = "https://www.kohls.com/"
5-
sb.activate_cdp_mode(url)
5+
sb.activate_cdp_mode(url, ad_block=True)
66
sb.sleep(2.6)
77
search = "Mickey Mouse Blanket"
88
req_1 = "Mickey"

examples/cdp_mode/raw_pokemon.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="en", guest=True) as sb:
3+
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
44
url = "https://www.pokemon.com/us"
55
sb.activate_cdp_mode(url)
66
sb.sleep(1.5)

help_docs/cdp_mode_methods.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ await tab.get_current_url()
326326
await tab.send_keys(selector, text, timeout=5)
327327
await tab.type(selector, text, timeout=5)
328328
await tab.click(selector, timeout=5)
329+
await tab.click_if_visible(selector, timeout=0)
329330
await tab.click_with_offset(selector, x, y, center=False, timeout=5)
330331
await tab.solve_captcha()
331332
await tab.click_captcha() # Same as solve_captcha()

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ wsproto==1.2.0;python_version<"3.10"
4444
wsproto~=1.3.2;python_version>="3.10"
4545
websocket-client~=1.9.0
4646
selenium==4.32.0;python_version<"3.10"
47-
selenium==4.39.0;python_version>="3.10"
47+
selenium==4.40.0;python_version>="3.10"
4848
cssselect==1.3.0
4949
nest-asyncio==1.6.0
5050
sortedcontainers==2.4.0
@@ -63,7 +63,7 @@ pytest-rerunfailures==16.1;python_version>="3.10"
6363
pytest-xdist==3.8.0
6464
parameterized==0.9.0
6565
behave==1.2.6
66-
soupsieve~=2.8.1
66+
soupsieve~=2.8.2
6767
beautifulsoup4~=4.14.3
6868
pyotp==2.9.0
6969
python-xlib==0.33;platform_system=="Linux"

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.45.13"
2+
__version__ = "4.46.0"

seleniumbase/core/sb_cdp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ def _on_a_g_recaptcha_page(self, *args, **kwargs):
19951995
time.sleep(0.1)
19961996
return True
19971997
elif "com/recaptcha/api.js" in source:
1998-
time.sleep(1.6) # Still loading
1998+
time.sleep(1.2) # Maybe still loading
19991999
try:
20002000
self.loop.run_until_complete(self.page.wait(0.1))
20012001
except Exception:
@@ -2084,10 +2084,10 @@ def __cdp_click_incapsula_hcaptcha(self):
20842084
with suppress(Exception):
20852085
element.click_with_offset(x_offset, y_offset)
20862086
was_clicked = True
2087-
time.sleep(0.056)
2087+
time.sleep(0.075)
20882088
if was_clicked:
20892089
# Wait a moment for the click to succeed
2090-
time.sleep(0.25)
2090+
time.sleep(0.75)
20912091
self.__slow_mode_pause_if_set()
20922092
self.loop.run_until_complete(self.page.wait())
20932093
if "--debug" in sys.argv:

0 commit comments

Comments
 (0)