Skip to content

Commit 55879ef

Browse files
committed
Update UC Mode / CDP Mode
1 parent d9b33dc commit 55879ef

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def uc_special_open_if_cf(
404404
special = True
405405
if status_str == "403" or status_str == "429":
406406
time.sleep(0.06) # Forbidden / Blocked! (Wait first!)
407-
if special:
407+
if special and not hasattr(driver, "cdp_base"):
408408
time.sleep(0.05)
409409
with driver:
410410
driver.execute_script('window.open("%s","_blank");' % url)
@@ -472,9 +472,12 @@ def uc_open_with_tab(driver, url):
472472
time.sleep(0.3)
473473
return
474474
if (url.startswith("http:") or url.startswith("https:")):
475-
with driver:
476-
driver.execute_script('window.open("%s","_blank");' % url)
477-
driver.close()
475+
if not hasattr(driver, "cdp_base"):
476+
with driver:
477+
driver.execute_script('window.open("%s","_blank");' % url)
478+
driver.close()
479+
else:
480+
driver.cdp.open(url)
478481
page_actions.switch_to_window(driver, driver.window_handles[-1], 2)
479482
else:
480483
driver.default_get(url) # The original one
@@ -492,9 +495,12 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
492495
reconnect_time = constants.UC.RECONNECT_TIME
493496
if (url.startswith("http:") or url.startswith("https:")):
494497
script = 'window.open("%s","_blank");' % url
495-
driver.execute_script(script)
496-
time.sleep(0.05)
497-
driver.close()
498+
if not hasattr(driver, "cdp_base"):
499+
driver.execute_script(script)
500+
time.sleep(0.05)
501+
driver.close()
502+
else:
503+
driver.cdp.open(url)
498504
if reconnect_time == "disconnect":
499505
driver.disconnect()
500506
time.sleep(0.008)

seleniumbase/fixtures/base_case.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8262,7 +8262,10 @@ def is_connected(self):
82628262
In CDP Mode, the CDP-Driver controls the web browser.
82638263
The CDP-Driver can be connected while WebDriver isn't.
82648264
"""
8265-
return self.driver.is_connected()
8265+
if hasattr(self.driver, "is_connected"):
8266+
return self.driver.is_connected()
8267+
else:
8268+
return True
82668269

82678270
def is_chromium(self):
82688271
"""Return True if the browser is Chrome or Edge."""

seleniumbase/undetected/cdp_driver/tab.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ async def find_elements_by_text(
493493
search_id, nresult = await self.send(
494494
cdp.dom.perform_search(text, True)
495495
)
496+
if not nresult:
497+
return []
496498
if nresult:
497499
node_ids = await self.send(
498500
cdp.dom.get_search_results(search_id, 0, nresult)
@@ -584,6 +586,8 @@ async def find_element_by_text(
584586
search_id, nresult = await self.send(
585587
cdp.dom.perform_search(text, True)
586588
)
589+
if not nresult:
590+
return
587591
node_ids = await self.send(
588592
cdp.dom.get_search_results(search_id, 0, nresult)
589593
)

0 commit comments

Comments
 (0)