Skip to content

Commit

Permalink
Update CDP Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmintz committed Feb 24, 2025
1 parent 1f581ed commit 1019b48
Showing 1 changed file with 20 additions and 10 deletions.
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

0 comments on commit 1019b48

Please sign in to comment.