Skip to content

CDP Mode: Patch 37 #3564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
sb.sleep(0.5)
sb.scroll_into_view("a#advSearch")
sb.sleep(0.5)
sb.cdp.mouse_click("a#advSearch")
sb.cdp.click("a#advSearch")
sb.sleep(1.2)
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
sb.cdp.assert_text("Pikachu", 'div[class*="title"]')
Expand Down
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_cf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
from seleniumbase import SB

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

with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
with SB(uc=True, test=True, locale_code="en", guest=True) as sb:
url = "https://www.cloudflare.com/login"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.sleep(3)
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
sb.sleep(2)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
sb.sleep(0.5)
sb.scroll_into_view("a#advSearch")
sb.sleep(0.5)
sb.cdp.mouse_click("a#advSearch")
sb.cdp.click("a#advSearch")
sb.sleep(1.2)
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
sb.cdp.assert_text("Pikachu", 'div[class*="title"]')
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.35.0"
__version__ = "4.35.1"
30 changes: 20 additions & 10 deletions seleniumbase/core/sb_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def find_elements_by_text(self, text, tag_name=None):
return updated_elements

def select(self, selector, timeout=None):
"""Similar to find_element(), but without text-based search."""
"""Similar to find_element()."""
if not timeout:
timeout = settings.SMALL_TIMEOUT
self.__add_light_pause()
Expand All @@ -297,12 +297,25 @@ def select(self, selector, timeout=None):
tag_name = selector.split(":contains(")[0].split(" ")[-1]
text = selector.split(":contains(")[1].split(")")[0][1:-1]
with suppress(Exception):
new_timeout = timeout
if new_timeout < 1:
new_timeout = 1
self.loop.run_until_complete(
self.page.select(tag_name, timeout=5)
self.page.select(tag_name, timeout=new_timeout)
)
self.loop.run_until_complete(self.page.find(text, timeout=5))
element = self.find_elements_by_text(text, tag_name=tag_name)[0]
return self.__add_sync_methods(element)
self.loop.run_until_complete(
self.page.find(text, timeout=new_timeout)
)
elements = self.find_elements_by_text(text, tag_name=tag_name)
if not elements:
plural = "s"
if timeout == 1:
plural = ""
msg = "\n Element {%s} was not found after %s second%s!"
message = msg % (selector, timeout, plural)
raise Exception(message)
element = self.__add_sync_methods(elements[0])
return element
failure = False
try:
element = self.loop.run_until_complete(
Expand All @@ -313,11 +326,8 @@ def select(self, selector, timeout=None):
plural = "s"
if timeout == 1:
plural = ""
message = "\n Element {%s} was not found after %s second%s!" % (
selector,
timeout,
plural,
)
msg = "\n Element {%s} was not found after %s second%s!"
message = msg % (selector, timeout, plural)
if failure:
raise Exception(message)
element = self.__add_sync_methods(element)
Expand Down
2 changes: 2 additions & 0 deletions seleniumbase/fixtures/js_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ def post_message(driver, message, msg_dur=None, style="info"):
set_messenger_theme(driver)
try:
execute_script(driver, messenger_script)
except TypeError:
pass
except Exception:
time.sleep(0.17)
activate_messenger(driver)
Expand Down
3 changes: 3 additions & 0 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,9 @@ def pytest_unconfigure(config):
"""This runs after all tests have completed with pytest."""
if "--co" in sys_argv or "--collect-only" in sys_argv:
return
reporter = config.pluginmanager.get_plugin("terminalreporter")
if not hasattr(reporter, "_sessionstarttime"):
return
if hasattr(sb_config, "_multithreaded") and sb_config._multithreaded:
import fasteners

Expand Down