Skip to content

Commit

Permalink
[py] do not allow Select class to work with disabled selects
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 11, 2022
1 parent f207270 commit 0eb286a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
2 changes: 2 additions & 0 deletions py/selenium/webdriver/support/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, webelement) -> None:
raise UnexpectedTagNameException(
"Select only works on <select> elements, not on <%s>" %
webelement.tag_name)
if not webelement.is_enabled():
raise NotImplementedError("Select element is disabled and may not be used.")
self._el = webelement
multi = self._el.get_dom_attribute("multiple")
self.is_multiple = multi and multi != "false"
Expand Down
38 changes: 7 additions & 31 deletions py/test/selenium/webdriver/common/select_class_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ def test_select_by_index_single(driver, pages):
assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_index(driver, pages):
pages.load("formPage.html")
sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
selected = sel.first_selected_option
sel.select_by_index(1)
assert selected == sel.first_selected_option


def test_select_by_value_single(driver, pages):
pages.load("formPage.html")
for select in [singleSelectValues1]:
Expand All @@ -60,16 +50,6 @@ def test_select_by_value_single(driver, pages):
assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_value(driver, pages):
pages.load("formPage.html")
sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
selected = sel.first_selected_option
sel.select_by_value('bar')
assert selected == sel.first_selected_option


def test_select_by_visible_text_single(driver, pages):
pages.load("formPage.html")

Expand Down Expand Up @@ -97,16 +77,6 @@ def test_select_by_visible_text_single(driver, pages):
# assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_visible_text(driver, pages):
pages.load("formPage.html")
sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
selected = sel.first_selected_option
sel.select_by_visible_text('Bar')
assert selected == sel.first_selected_option


def test_select_by_index_multiple(driver, pages):
pages.load("formPage.html")

Expand Down Expand Up @@ -247,7 +217,7 @@ def test_get_options(driver, pages):

def test_get_all_selected_options_single(driver, pages):
pages.load("formPage.html")
for select in [singleSelectValues1, singleSelectValues2, disabledSelect]:
for select in [singleSelectValues1, singleSelectValues2]:
opts = Select(driver.find_element(By.NAME, select['name'])).all_selected_options
assert len(opts) == 1
assert opts[0].text == select['values'][0]
Expand Down Expand Up @@ -284,6 +254,12 @@ def test_raises_exception_for_invalid_tag_name(driver, pages):
Select(driver.find_element(By.TAG_NAME, "div"))


def test_raises_exception_for_disabled_element(driver, pages):
pages.load("formPage.html")
with pytest.raises(NotImplementedError):
Select(driver.find_element(By.NAME, disabledSelect["name"]))


def test_deselect_by_index_non_existent(driver, pages):
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
Expand Down

0 comments on commit 0eb286a

Please sign in to comment.