Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

--headless vs --headless=chrome vs --headless=new in Selenium

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:

  1. What is the difference between --headless, --headless=chrome and --headless=new?
  2. Which should I use, --headless, --headless=chrome or --headless=new?
like image 526
Kai - Kazuya Ito Avatar asked Oct 23 '25 16:10

Kai - Kazuya Ito


1 Answers

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")
like image 109
Michael Mintz Avatar answered Oct 26 '25 04:10

Michael Mintz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!