I'm learning Selenium with Django and Google Chrome. *I use Selenium 4.11.2.
Then, I tested with --headless, --headless=chrome and --headless=new as shown below, then all work properly:
from django.test import LiveServerTestCase
from selenium import webdriver
class TestBrowser(LiveServerTestCase):
def test_example(self):
options = webdriver.ChromeOptions()
options.add_argument("--headless") # Here
driver = webdriver.Chrome(options=options)
driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in driver.title
from django.test import LiveServerTestCase
from selenium import webdriver
class TestBrowser(LiveServerTestCase):
def test_example(self):
options = webdriver.ChromeOptions()
options.add_argument("--headless=chrome") # Here
driver = webdriver.Chrome(options=options)
driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in driver.title
from django.test import LiveServerTestCase
from selenium import webdriver
class TestBrowser(LiveServerTestCase):
def test_example(self):
options = webdriver.ChromeOptions()
options.add_argument("--headless=new") # Here
driver = webdriver.Chrome(options=options)
driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in driver.title
My questions:
--headless, --headless=chrome and --headless=new?--headless, --headless=chrome or --headless=new?The differences are explained here: https://stackoverflow.com/a/73840130/7058266
First came --headless. Then --headless=chrome was added in Chrome 96. Then the new one was renamed in Chrome 109 to --headless=new. The newer one makes headless Chrome work exactly like regular Chrome, but it's slightly slower than the old headless Chrome because it has the same backend code that regular Chrome has.
Usage:
options.add_argument("--headless=new")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With