Skip to content

CDP Mode - Patch 33 #3514

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 4 commits into from
Feb 13, 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/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .google_objects import HomePage, ResultsPage
except Exception:
from google_objects import HomePage, ResultsPage
BaseCase.main(__name__, __file__)
BaseCase.main(__name__, __file__, "--uc")


class GoogleTests(BaseCase):
Expand Down
2 changes: 1 addition & 1 deletion examples/boilerplates/samples/test_page_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""An example using the Classic Page Object Model."""
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
BaseCase.main(__name__, __file__, "--uc")


class GooglePage:
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_priceline.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
sb.sleep(0.8)
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(1.25)
sb.sleep(0.75)
hotel_names = sb.find_elements('a[data-autobot-element-id*="HOTEL_NAME"]')
hotel_prices = sb.find_elements('span[font-size="4,,,5"]')
print("Priceline Hotels in %s:" % location)
Expand Down
2 changes: 1 addition & 1 deletion examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def test_presentation_4(self):
sb.sleep(0.8)
for y in range(1, 9):
sb.scroll_to_y(y * 400)
sb.sleep(1.25)
sb.sleep(0.75)
hotel_names = sb.find_elements(
'a[data-autobot-element-id*="HOTEL_NAME"]'
)
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_google.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from seleniumbase import SB

with SB(test=True) as sb:
with SB(test=True, uc=True) as sb:
sb.open("https://google.com/ncr")
sb.type('[title="Search"]', "SeleniumBase GitHub page\n")
sb.click('[href*="github.com/seleniumbase/"]')
Expand Down
4 changes: 2 additions & 2 deletions examples/raw_gui_click.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from seleniumbase import SB

# An incomplete UserAgent forces CAPTCHA-solving on macOS
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
# An bad UserAgent forces CAPTCHA-solving on macOS
agent = "cool"
if "linux" in sys.platform or "win32" in sys.platform:
agent = None # Use the default UserAgent

Expand Down
4 changes: 2 additions & 2 deletions examples/raw_pyautogui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from seleniumbase import SB

# An incomplete UserAgent forces CAPTCHA-solving on macOS
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
# An bad UserAgent forces CAPTCHA-solving on macOS
agent = "cool"
if "linux" in sys.platform or "win32" in sys.platform:
agent = None # Use the default UserAgent

Expand Down
4 changes: 2 additions & 2 deletions examples/test_cdp_ad_blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
class CDPNetworkBlockingTests(BaseCase):
def test_cdp_network_blocking(self):
self.open("about:blank")
if not self.is_chromium():
message = "This test is only for Chromium browsers!"
if self._reuse_session or not self.is_chromium():
message = "Skipping test if reusing session or not Chromium!"
print(message)
self.skip(message)
self.execute_cdp_cmd(
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pathspec==0.12.1
Babel==2.17.0
paginate==0.5.7
mkdocs==1.6.1
mkdocs-material==9.6.3
mkdocs-material==9.6.4
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
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.34.13"
__version__ = "4.34.14"
26 changes: 16 additions & 10 deletions seleniumbase/undetected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,20 @@ def reconnect(self, timeout=0.1):
self.start_session()
time.sleep(0.0075)
with suppress(Exception):
for i in range(5):
if self.current_url.startswith("chrome-extension://"):
for window_handle in self.window_handles:
self.switch_to.window(window_handle)
if self.current_url.startswith(
"chrome-extension://"
):
self.close()
if self.service.is_connectable():
self.stop_client()
self.service.stop()
self.service.start()
self.start_session()
time.sleep(0.0075)
else:
break
time.sleep(0.003)
with suppress(Exception):
self.switch_to.window(self.window_handles[-1])
self._is_connected = True

def disconnect(self):
Expand All @@ -487,17 +490,20 @@ def connect(self):
self.start_session()
time.sleep(0.0075)
with suppress(Exception):
for i in range(5):
if self.current_url.startswith("chrome-extension://"):
for window_handle in self.window_handles:
self.switch_to.window(window_handle)
if self.current_url.startswith(
"chrome-extension://"
):
self.close()
if self.service.is_connectable():
self.stop_client()
self.service.stop()
self.service.start()
self.start_session()
time.sleep(0.0075)
else:
break
time.sleep(0.003)
with suppress(Exception):
self.switch_to.window(self.window_handles[-1])
self._is_connected = True

def start_session(self, capabilities=None):
Expand Down
5 changes: 3 additions & 2 deletions seleniumbase/undetected/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def uc_click(
driver.js_click(selector, by=by, timeout=1)
else:
super().click()
driver = self._parent
if not reconnect_time:
self._parent.reconnect(0.5)
driver.reconnect(0.5)
else:
self._parent.reconnect(reconnect_time)
driver.reconnect(reconnect_time)

def uc_reconnect(self, reconnect_time=None):
if not reconnect_time:
Expand Down