diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index bcdc747571..f234fc2393 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -99,6 +99,28 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase): timeout ) + def wait_until_visible(self, css_selector, timeout=10): + """ + Block until the element described by the CSS selector is visible. + """ + from selenium.webdriver.common.by import By + from selenium.webdriver.support import expected_conditions as ec + self.wait_until( + ec.visibility_of_element_located((By.CSS_SELECTOR, css_selector)), + timeout + ) + + def wait_until_invisible(self, css_selector, timeout=10): + """ + Block until the element described by the CSS selector is invisible. + """ + from selenium.webdriver.common.by import By + from selenium.webdriver.support import expected_conditions as ec + self.wait_until( + ec.invisibility_of_element_located((By.CSS_SELECTOR, css_selector)), + timeout + ) + def wait_page_loaded(self): """ Block until page has started to load. diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py index 0f8ad4bc25..f59f87e6de 100644 --- a/tests/admin_inlines/tests.py +++ b/tests/admin_inlines/tests.py @@ -879,19 +879,19 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): self.admin_login(username='super', password='secret') self.selenium.get(self.live_server_url + reverse('admin:admin_inlines_author_add')) # One field is in a stacked inline, other in a tabular one. - test_fields = ['id_nonautopkbook_set-0-title', 'id_nonautopkbook_set-2-0-title'] + test_fields = ['#id_nonautopkbook_set-0-title', '#id_nonautopkbook_set-2-0-title'] show_links = self.selenium.find_elements_by_link_text('SHOW') self.assertEqual(len(show_links), 2) for show_index, field_name in enumerate(test_fields, 0): - self.assertFalse(self.selenium.find_element_by_id(field_name).is_displayed()) + self.wait_until_invisible(field_name) show_links[show_index].click() - self.assertTrue(self.selenium.find_element_by_id(field_name).is_displayed()) + self.wait_until_visible(field_name) hide_links = self.selenium.find_elements_by_link_text('HIDE') self.assertEqual(len(hide_links), 2) for hide_index, field_name in enumerate(test_fields, 0): - self.assertTrue(self.selenium.find_element_by_id(field_name).is_displayed()) + self.wait_until_visible(field_name) hide_links[hide_index].click() - self.assertFalse(self.selenium.find_element_by_id(field_name).is_displayed()) + self.wait_until_invisible(field_name) class SeleniumChromeTests(SeleniumFirefoxTests):