mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
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`.
This commit is contained in:
@@ -951,6 +951,7 @@ subclass which provides that functionality. Replace it with
|
||||
The code for this test may look as follows::
|
||||
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.firefox.webdriver import WebDriver
|
||||
|
||||
class MySeleniumTests(StaticLiveServerTestCase):
|
||||
@@ -969,11 +970,11 @@ The code for this test may look as follows::
|
||||
|
||||
def test_login(self):
|
||||
self.selenium.get('%s%s' % (self.live_server_url, '/login/'))
|
||||
username_input = self.selenium.find_element_by_name("username")
|
||||
username_input = self.selenium.find_element(By.NAME, "username")
|
||||
username_input.send_keys('myuser')
|
||||
password_input = self.selenium.find_element_by_name("password")
|
||||
password_input = self.selenium.find_element(By.NAME, "password")
|
||||
password_input.send_keys('secret')
|
||||
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
|
||||
self.selenium.find_element(By.XPATH, '//input[@value="Log in"]').click()
|
||||
|
||||
Finally, you may run the test as follows:
|
||||
|
||||
@@ -1011,10 +1012,10 @@ out the `full reference`_ for more details.
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
timeout = 2
|
||||
...
|
||||
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
|
||||
self.selenium.find_element(By.XPATH, '//input[@value="Log in"]').click()
|
||||
# Wait until the response is received
|
||||
WebDriverWait(self.selenium, timeout).until(
|
||||
lambda driver: driver.find_element_by_tag_name('body'))
|
||||
lambda driver: driver.find_element(By.TAG_NAME, 'body'))
|
||||
|
||||
The tricky thing here is that there's really no such thing as a "page load,"
|
||||
especially in modern web apps that generate HTML dynamically after the
|
||||
|
||||
Reference in New Issue
Block a user