From 2ccc0b22db6730ba0950b10bbc5238ae575e4a45 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 20 Oct 2021 15:54:30 +0200 Subject: [PATCH] Fixed #33211 -- Updated tests for Selenium 4.0.0. Replaced deprecated `find_element[s]_by_*()` usages, in favour of `find_element[s]()` with an explicit `By`. --- django/contrib/admin/tests.py | 33 ++-- docs/topics/testing/tools.txt | 11 +- tests/admin_changelist/tests.py | 47 +++-- tests/admin_inlines/tests.py | 174 +++++++++------- tests/admin_views/test_autocomplete_view.py | 44 +++-- tests/admin_views/test_nav_sidebar.py | 28 +-- tests/admin_views/tests.py | 209 +++++++++++--------- tests/admin_widgets/tests.py | 163 ++++++++------- tests/forms_tests/tests/test_widgets.py | 3 +- tests/view_tests/tests/test_i18n.py | 24 +-- 10 files changed, 411 insertions(+), 325 deletions(-) diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index 1e51542fa2..36e2fe5c90 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -116,8 +116,9 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase): """ Block until a new page has loaded and is ready. """ + from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as ec - old_page = self.selenium.find_element_by_tag_name('html') + old_page = self.selenium.find_element(By.TAG_NAME, 'html') yield # Wait for the next page to be loaded self.wait_until(ec.staleness_of(old_page), timeout=timeout) @@ -127,22 +128,24 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase): """ Log in to the admin. """ + from selenium.webdriver.common.by import By self.selenium.get('%s%s' % (self.live_server_url, login_url)) - username_input = self.selenium.find_element_by_name('username') + username_input = self.selenium.find_element(By.NAME, 'username') username_input.send_keys(username) - password_input = self.selenium.find_element_by_name('password') + password_input = self.selenium.find_element(By.NAME, 'password') password_input.send_keys(password) login_text = _('Log in') with self.wait_page_loaded(): - self.selenium.find_element_by_xpath('//input[@value="%s"]' % login_text).click() + self.selenium.find_element(By.XPATH, '//input[@value="%s"]' % login_text).click() def select_option(self, selector, value): """ Select the