Skip to content

Commit 6d8187a

Browse files
committed
Add "NoSuchOptionException" for missing "<select>" options
1 parent be477fa commit 6d8187a

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

seleniumbase/common/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" SeleniumBase Exceptions
22
NoSuchFileException => Called when self.assert_downloaded_file(...) fails.
3+
NoSuchOptionException => Called when select_option_by_*() lacks the option.
34
NotConnectedException => Called when Internet is not reachable when needed.
45
NotUsingChromeException => Used by Chrome-only methods if not using Chrome.
56
NotUsingChromiumException => Used by Chromium-only methods if not Chromium.
@@ -15,6 +16,10 @@ class NoSuchFileException(Exception):
1516
pass
1617

1718

19+
class NoSuchOptionException(Exception):
20+
pass
21+
22+
1823
class NotConnectedException(Exception):
1924
pass
2025

seleniumbase/fixtures/base_case.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,11 +2829,38 @@ def __select_option(
28292829
except Exception:
28302830
self.wait_for_ready_state_complete()
28312831
if option_by == "index":
2832-
Select(element).select_by_index(option)
2832+
try:
2833+
Select(element).select_by_index(option)
2834+
except Exception:
2835+
msg = (
2836+
"Element {%s} has no selectable index option {%s}!"
2837+
% (dropdown_selector, option)
2838+
)
2839+
page_actions.timeout_exception(
2840+
"NoSuchOptionException", msg
2841+
)
28332842
elif option_by == "value":
2834-
Select(element).select_by_value(option)
2843+
try:
2844+
Select(element).select_by_value(option)
2845+
except Exception:
2846+
msg = (
2847+
"Element {%s} has no selectable value option {%s}!"
2848+
% (dropdown_selector, option)
2849+
)
2850+
page_actions.timeout_exception(
2851+
"NoSuchOptionException", msg
2852+
)
28352853
else:
2836-
Select(element).select_by_visible_text(option)
2854+
try:
2855+
Select(element).select_by_visible_text(option)
2856+
except Exception:
2857+
msg = (
2858+
"Element {%s} has no selectable text option {%s}!"
2859+
% (dropdown_selector, option)
2860+
)
2861+
page_actions.timeout_exception(
2862+
"NoSuchOptionException", msg
2863+
)
28372864
time.sleep(0.05)
28382865
self.wait_for_ready_state_complete()
28392866
latest_window_count = len(self.driver.window_handles)

seleniumbase/fixtures/shared_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def format_exc(exception, message):
123123
from selenium.common.exceptions import NoSuchFrameException
124124
from selenium.common.exceptions import NoSuchWindowException
125125
from seleniumbase.common.exceptions import NoSuchFileException
126+
from seleniumbase.common.exceptions import NoSuchOptionException
126127
from seleniumbase.common.exceptions import TextNotVisibleException
127128
from seleniumbase.common import exceptions
128129

@@ -161,6 +162,10 @@ def format_exc(exception, message):
161162
exc = exceptions.NoSuchFileException
162163
elif exception == "NoSuchFileException":
163164
exc = exceptions.NoSuchFileException
165+
elif exception == NoSuchOptionException:
166+
exc = exceptions.NoSuchOptionException
167+
elif exception == "NoSuchOptionException":
168+
exc = exceptions.NoSuchOptionException
164169
elif type(exception) is str:
165170
exc = Exception
166171
message = "%s: %s" % (exception, message)

0 commit comments

Comments
 (0)