Since Selenium 4.6.0, you don't need to manually install Selenium Manager(webdriver-manager) as shown below because it is already included in Selenium according to the blog:
pip install webdriver-manager
And, since Selenium 4.11.0, the code below is basically enough because Selenium Manager can automatically discover your browser version installed in your machine, then can automatically download the proper driver version for it according to the blog:
from selenium import webdriver
driver = webdriver.Chrome()
In addition, the examples below can test Django Admin with Chrome, Selenium, pytest-django and Django. *My answer explains how to test Django Admin with multiple Headless browsers(Chrome, Microsoft Edge and Firefox), Selenium, pytest-django and Django:
# "tests/test_1.py"
import pytest
from selenium import webdriver
from django.test import LiveServerTestCase
@pytest.fixture(scope="class")
def chrome_driver_init(request):
chrome_driver = webdriver.Chrome()
request.cls.driver = chrome_driver
yield
chrome_driver.close()
@pytest.mark.usefixtures("chrome_driver_init")
class Test_URL_Chrome(LiveServerTestCase):
def test_open_url(self):
self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in self.driver.title
Or:
# "tests/conftest.py"
import pytest
from selenium import webdriver
@pytest.fixture(scope="class")
def chrome_driver_init(request):
chrome_driver = webdriver.Chrome()
request.cls.driver = chrome_driver
yield
chrome_driver.close()
# "tests/test_1.py"
import pytest
from django.test import LiveServerTestCase
@pytest.mark.usefixtures("chrome_driver_init")
class Test_URL_Chrome(LiveServerTestCase):
def test_open_url(self):
self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in self.driver.title
chromedriver.exe
in the same directory as your Python script. – Leprosechoco install chromedriver
. – Rabbit