Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2d890e

Browse files
committed
Add more select options for CDP Mode
1 parent ae9021d commit b2d890e

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

‎examples/cdp_mode/ReadMe.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ sb.cdp.mouse_click(selector, timeout=None)
399399
sb.cdp.nested_click(parent_selector, selector)
400400
sb.cdp.get_nested_element(parent_selector, selector)
401401
sb.cdp.select_option_by_text(dropdown_selector, option)
402+
sb.cdp.select_option_by_index(dropdown_selector, option)
403+
sb.cdp.select_option_by_value(dropdown_selector, option)
402404
sb.cdp.flash(selector, duration=1, color="44CC88", pause=0)
403405
sb.cdp.highlight(selector)
404406
sb.cdp.focus(selector)

‎seleniumbase/core/browser_launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
808808
cdp.get_window_size = CDPM.get_window_size
809809
cdp.nested_click = CDPM.nested_click
810810
cdp.select_option_by_text = CDPM.select_option_by_text
811+
cdp.select_option_by_index = CDPM.select_option_by_index
812+
cdp.select_option_by_value = CDPM.select_option_by_value
811813
cdp.flash = CDPM.flash
812814
cdp.highlight = CDPM.highlight
813815
cdp.focus = CDPM.focus

‎seleniumbase/core/sb_cdp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,37 @@ def select_option_by_text(self, dropdown_selector, option):
823823
% (dropdown_selector, option)
824824
)
825825

826+
def select_option_by_index(self, dropdown_selector, option):
827+
element = self.find_element(dropdown_selector)
828+
element.scroll_into_view()
829+
options = element.query_selector_all("option")
830+
count = 0
831+
for found_option in options:
832+
if count == int(option):
833+
found_option.select_option()
834+
return
835+
count += 1
836+
raise Exception(
837+
"Unable to find index option {%s} in dropdown {%s}!"
838+
% (dropdown_selector, option)
839+
)
840+
841+
def select_option_by_value(self, dropdown_selector, option):
842+
element = self.find_element(dropdown_selector)
843+
element.scroll_into_view()
844+
options = element.query_selector_all("option")
845+
for found_option in options:
846+
if (
847+
"value" in found_option.attrs
848+
and str(found_option.attrs["value"]) == str(option)
849+
):
850+
found_option.select_option()
851+
return
852+
raise Exception(
853+
"Unable to find value option {%s} in dropdown {%s}!"
854+
% (dropdown_selector, option)
855+
)
856+
826857
def flash(
827858
self,
828859
selector, # The CSS Selector to flash

‎seleniumbase/fixtures/base_case.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,9 @@ def select_option_by_index(
31983198
timeout = settings.SMALL_TIMEOUT
31993199
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
32003200
timeout = self.__get_new_timeout(timeout)
3201+
if self.__is_cdp_swap_needed():
3202+
self.cdp.select_option_by_index(dropdown_selector, option)
3203+
return
32013204
self.__select_option(
32023205
dropdown_selector,
32033206
option,
@@ -3222,6 +3225,9 @@ def select_option_by_value(
32223225
timeout = settings.SMALL_TIMEOUT
32233226
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
32243227
timeout = self.__get_new_timeout(timeout)
3228+
if self.__is_cdp_swap_needed():
3229+
self.cdp.select_option_by_value(dropdown_selector, option)
3230+
return
32253231
self.__select_option(
32263232
dropdown_selector,
32273233
option,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /