From bbc1663d0990e4b3bd66e0f55bdfb7ec19bff8ac Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 13 Oct 2022 22:22:38 -0500 Subject: [PATCH] Revert "[py] do not allow Select class to work with disabled selects" This reverts commit 0eb286a8 --- py/selenium/webdriver/support/select.py | 6 +-- .../webdriver/common/select_class_tests.py | 38 +++++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/py/selenium/webdriver/support/select.py b/py/selenium/webdriver/support/select.py index 355ea8a306b53..b5abb4f7d586d 100644 --- a/py/selenium/webdriver/support/select.py +++ b/py/selenium/webdriver/support/select.py @@ -35,10 +35,8 @@ def __init__(self, webelement) -> None: """ if webelement.tag_name.lower() != "select": raise UnexpectedTagNameException( - "Select only works on elements, not on <%s>" % + webelement.tag_name) self._el = webelement multi = self._el.get_dom_attribute("multiple") self.is_multiple = multi and multi != "false" diff --git a/py/test/selenium/webdriver/common/select_class_tests.py b/py/test/selenium/webdriver/common/select_class_tests.py index 4e807fbf3aaba..10bf8828ea1e7 100644 --- a/py/test/selenium/webdriver/common/select_class_tests.py +++ b/py/test/selenium/webdriver/common/select_class_tests.py @@ -55,6 +55,16 @@ def test_raises_exception_select_by_index_single_disabled(driver, pages): sel.select_by_index(1) +@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]: @@ -71,6 +81,16 @@ def test_raises_exception_select_by_value_single_disabled(driver, pages): sel.select_by_value(disabledSingleSelect["values"][1].lower()) +@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") @@ -89,6 +109,16 @@ def test_raises_exception_select_by_text_single_disabled(driver, pages): sel.select_by_visible_text(disabledSingleSelect["values"][1]) +@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") @@ -253,7 +283,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]: + for select in [singleSelectValues1, singleSelectValues2, disabledSelect]: opts = Select(driver.find_element(By.NAME, select["name"])).all_selected_options assert len(opts) == 1 assert opts[0].text == select["values"][0] @@ -290,12 +320,6 @@ 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]: