Skip to content

Commit 5d732a4

Browse files
authored
Merge pull request #3564 from seleniumbase/cdp-mode-patch-37
CDP Mode: Patch 37
2 parents 1f581ed + 5d57b3e commit 5d732a4

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

examples/cdp_mode/ReadMe.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
144144
sb.sleep(0.5)
145145
sb.scroll_into_view("a#advSearch")
146146
sb.sleep(0.5)
147-
sb.cdp.mouse_click("a#advSearch")
147+
sb.cdp.click("a#advSearch")
148148
sb.sleep(1.2)
149149
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
150150
sb.cdp.assert_text("Pikachu", 'div[class*="title"]')

examples/cdp_mode/raw_cf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
22
from seleniumbase import SB
33

4-
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
4+
with SB(uc=True, test=True, locale_code="en", guest=True) as sb:
55
url = "https://www.cloudflare.com/login"
66
sb.activate_cdp_mode(url)
77
sb.sleep(3)
88
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
99
sb.sleep(2)
1010

11-
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
11+
with SB(uc=True, test=True, locale_code="en", guest=True) as sb:
1212
url = "https://www.cloudflare.com/login"
1313
sb.activate_cdp_mode(url)
14-
sb.sleep(2)
14+
sb.sleep(3)
1515
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
1616
sb.sleep(2)

examples/cdp_mode/raw_pokemon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
sb.sleep(0.5)
1515
sb.scroll_into_view("a#advSearch")
1616
sb.sleep(0.5)
17-
sb.cdp.mouse_click("a#advSearch")
17+
sb.cdp.click("a#advSearch")
1818
sb.sleep(1.2)
1919
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
2020
sb.cdp.assert_text("Pikachu", 'div[class*="title"]')

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.35.0"
2+
__version__ = "4.35.1"

seleniumbase/core/sb_cdp.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def find_elements_by_text(self, text, tag_name=None):
288288
return updated_elements
289289

290290
def select(self, selector, timeout=None):
291-
"""Similar to find_element(), but without text-based search."""
291+
"""Similar to find_element()."""
292292
if not timeout:
293293
timeout = settings.SMALL_TIMEOUT
294294
self.__add_light_pause()
@@ -297,12 +297,25 @@ def select(self, selector, timeout=None):
297297
tag_name = selector.split(":contains(")[0].split(" ")[-1]
298298
text = selector.split(":contains(")[1].split(")")[0][1:-1]
299299
with suppress(Exception):
300+
new_timeout = timeout
301+
if new_timeout < 1:
302+
new_timeout = 1
300303
self.loop.run_until_complete(
301-
self.page.select(tag_name, timeout=5)
304+
self.page.select(tag_name, timeout=new_timeout)
302305
)
303-
self.loop.run_until_complete(self.page.find(text, timeout=5))
304-
element = self.find_elements_by_text(text, tag_name=tag_name)[0]
305-
return self.__add_sync_methods(element)
306+
self.loop.run_until_complete(
307+
self.page.find(text, timeout=new_timeout)
308+
)
309+
elements = self.find_elements_by_text(text, tag_name=tag_name)
310+
if not elements:
311+
plural = "s"
312+
if timeout == 1:
313+
plural = ""
314+
msg = "\n Element {%s} was not found after %s second%s!"
315+
message = msg % (selector, timeout, plural)
316+
raise Exception(message)
317+
element = self.__add_sync_methods(elements[0])
318+
return element
306319
failure = False
307320
try:
308321
element = self.loop.run_until_complete(
@@ -313,11 +326,8 @@ def select(self, selector, timeout=None):
313326
plural = "s"
314327
if timeout == 1:
315328
plural = ""
316-
message = "\n Element {%s} was not found after %s second%s!" % (
317-
selector,
318-
timeout,
319-
plural,
320-
)
329+
msg = "\n Element {%s} was not found after %s second%s!"
330+
message = msg % (selector, timeout, plural)
321331
if failure:
322332
raise Exception(message)
323333
element = self.__add_sync_methods(element)

seleniumbase/fixtures/js_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,8 @@ def post_message(driver, message, msg_dur=None, style="info"):
950950
set_messenger_theme(driver)
951951
try:
952952
execute_script(driver, messenger_script)
953+
except TypeError:
954+
pass
953955
except Exception:
954956
time.sleep(0.17)
955957
activate_messenger(driver)

seleniumbase/plugins/pytest_plugin.py

+3
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,9 @@ def pytest_unconfigure(config):
24962496
"""This runs after all tests have completed with pytest."""
24972497
if "--co" in sys_argv or "--collect-only" in sys_argv:
24982498
return
2499+
reporter = config.pluginmanager.get_plugin("terminalreporter")
2500+
if not hasattr(reporter, "_sessionstarttime"):
2501+
return
24992502
if hasattr(sb_config, "_multithreaded") and sb_config._multithreaded:
25002503
import fasteners
25012504

0 commit comments

Comments
 (0)