summaryrefslogtreecommitdiff
path: root/django/contrib/admin/tests.py
diff options
context:
space:
mode:
authorJohannes Hoppe <info@johanneshoppe.com>2019-11-27 22:34:07 +0700
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-11-27 16:34:07 +0100
commit249a6190aef5e3676c6d9aa6c38cecff895b5993 (patch)
treef2ef8036d6e64478c2273caeaf78a247a8708858 /django/contrib/admin/tests.py
parent69dbb6b7086699bea27609845b1cd89fd2f85e0b (diff)
Fixed #30975 -- Replaced custom get_select_option with Selenium's select_by_value.
Diffstat (limited to 'django/contrib/admin/tests.py')
-rw-r--r--django/contrib/admin/tests.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py
index 86745202a9..5ea233ad5e 100644
--- a/django/contrib/admin/tests.py
+++ b/django/contrib/admin/tests.py
@@ -141,17 +141,23 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
return self.selenium.execute_script(
'return django.jQuery("%s").css("%s")' % (selector, attribute))
- def get_select_option(self, selector, value):
+ def select_option(self, selector, value):
"""
- Return the <OPTION> with the value `value` inside the <SELECT> widget
+ Select the <OPTION> with the value `value` inside the <SELECT> widget
identified by the CSS selector `selector`.
"""
- from selenium.common.exceptions import NoSuchElementException
- options = self.selenium.find_elements_by_css_selector('%s > option' % selector)
- for option in options:
- if option.get_attribute('value') == value:
- return option
- raise NoSuchElementException('Option "%s" not found in "%s"' % (value, selector))
+ from selenium.webdriver.support.ui import Select
+ select = Select(self.selenium.find_element_by_css_selector(selector))
+ select.select_by_value(value)
+
+ def deselect_option(self, selector, value):
+ """
+ Deselect the <OPTION> with the value `value` inside the <SELECT> widget
+ identified by the CSS selector `selector`.
+ """
+ from selenium.webdriver.support.ui import Select
+ select = Select(self.selenium.find_element_by_css_selector(selector))
+ select.deselect_by_value(value)
def _assertOptionsValues(self, options_selector, values):
if values: