Add "NoSuchOptionException" for missing "<select>" options
This commit is contained in:
parent
be477faa56
commit
6d8187a315
|
@ -1,5 +1,6 @@
|
|||
""" SeleniumBase Exceptions
|
||||
NoSuchFileException => Called when self.assert_downloaded_file(...) fails.
|
||||
NoSuchOptionException => Called when select_option_by_*() lacks the option.
|
||||
NotConnectedException => Called when Internet is not reachable when needed.
|
||||
NotUsingChromeException => Used by Chrome-only methods if not using Chrome.
|
||||
NotUsingChromiumException => Used by Chromium-only methods if not Chromium.
|
||||
|
@ -15,6 +16,10 @@ class NoSuchFileException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class NoSuchOptionException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NotConnectedException(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -2829,11 +2829,38 @@ class BaseCase(unittest.TestCase):
|
|||
except Exception:
|
||||
self.wait_for_ready_state_complete()
|
||||
if option_by == "index":
|
||||
Select(element).select_by_index(option)
|
||||
try:
|
||||
Select(element).select_by_index(option)
|
||||
except Exception:
|
||||
msg = (
|
||||
"Element {%s} has no selectable index option {%s}!"
|
||||
% (dropdown_selector, option)
|
||||
)
|
||||
page_actions.timeout_exception(
|
||||
"NoSuchOptionException", msg
|
||||
)
|
||||
elif option_by == "value":
|
||||
Select(element).select_by_value(option)
|
||||
try:
|
||||
Select(element).select_by_value(option)
|
||||
except Exception:
|
||||
msg = (
|
||||
"Element {%s} has no selectable value option {%s}!"
|
||||
% (dropdown_selector, option)
|
||||
)
|
||||
page_actions.timeout_exception(
|
||||
"NoSuchOptionException", msg
|
||||
)
|
||||
else:
|
||||
Select(element).select_by_visible_text(option)
|
||||
try:
|
||||
Select(element).select_by_visible_text(option)
|
||||
except Exception:
|
||||
msg = (
|
||||
"Element {%s} has no selectable text option {%s}!"
|
||||
% (dropdown_selector, option)
|
||||
)
|
||||
page_actions.timeout_exception(
|
||||
"NoSuchOptionException", msg
|
||||
)
|
||||
time.sleep(0.05)
|
||||
self.wait_for_ready_state_complete()
|
||||
latest_window_count = len(self.driver.window_handles)
|
||||
|
|
|
@ -123,6 +123,7 @@ def format_exc(exception, message):
|
|||
from selenium.common.exceptions import NoSuchFrameException
|
||||
from selenium.common.exceptions import NoSuchWindowException
|
||||
from seleniumbase.common.exceptions import NoSuchFileException
|
||||
from seleniumbase.common.exceptions import NoSuchOptionException
|
||||
from seleniumbase.common.exceptions import TextNotVisibleException
|
||||
from seleniumbase.common import exceptions
|
||||
|
||||
|
@ -161,6 +162,10 @@ def format_exc(exception, message):
|
|||
exc = exceptions.NoSuchFileException
|
||||
elif exception == "NoSuchFileException":
|
||||
exc = exceptions.NoSuchFileException
|
||||
elif exception == NoSuchOptionException:
|
||||
exc = exceptions.NoSuchOptionException
|
||||
elif exception == "NoSuchOptionException":
|
||||
exc = exceptions.NoSuchOptionException
|
||||
elif type(exception) is str:
|
||||
exc = Exception
|
||||
message = "%s: %s" % (exception, message)
|
||||
|
|
Loading…
Reference in New Issue