summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2021-10-20 15:54:30 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-10-21 14:37:16 +0200
commit2ccc0b22db6730ba0950b10bbc5238ae575e4a45 (patch)
tree6107a609c42128b51ae7a5c50805912ba613b8d2 /docs
parent8fa974fcdde90b6719a1058e77541389ff1809b5 (diff)
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`.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/testing/tools.txt11
1 files changed, 6 insertions, 5 deletions
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 3d955503b1..fbb2e88e1d 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -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