|
| 1 | +--- |
| 2 | +title: "Headless is Going Away!" |
| 3 | +linkTitle: "Headless is Going Away!" |
| 4 | +date: 2023-01-29 |
| 5 | +tags: ["selenium"] |
| 6 | +categories: ["releases"] |
| 7 | +author: Diego Molina ([@diegofmolina](https://twitter.com/diegofmolina)) |
| 8 | +description: > |
| 9 | + Now that we got your attention, headless is not actually going away, just the convenience method to set it in Selenium |
| 10 | +--- |
| 11 | + |
| 12 | +Headless is an execution mode for Firefox and Chromium based browsers. It allows users to run automated scripts in |
| 13 | +headless mode, meaning that the browser window wouldn’t be visible. In most of Selenium's bindings there is a |
| 14 | +convenience method to set this execution mode while setting the browser options. However, |
| 15 | +[Selenium 4.8.0](https://www.selenium.dev/blog/2023/selenium-4-8-0-released/) will be deprecated this method and |
| 16 | +and now users need to set it through arguments when setting the browser options. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +Now that we got your attention, |
| 21 | +We're very happy to announce the release of Selenium 4.8.0 for Java, |
| 22 | +.NET, Ruby, Python, and Javascript as well as the Grid and Internet Explorer Driver. |
| 23 | +Links to everything can be found on our [downloads page][downloads]. |
| 24 | + |
| 25 | +### Why is Selenium doing this? |
| 26 | + |
| 27 | +Chromium based browsers have now two different headless modes (the original one, and one with more |
| 28 | +capabilities added in 2022). When a user sets headless to `true` via the convenience method in Selenium, |
| 29 | +it is using the initial method provided by Chromium based browsers. |
| 30 | + |
| 31 | +By deprecating the convenience method (and removing it in Selenium 4.10.0), users will be in full control to |
| 32 | +choose which headless mode they want to use. |
| 33 | + |
| 34 | +### What are the two headless modes? |
| 35 | + |
| 36 | +The traditional `--headless`, and since version 96, Chrome has a new headless mode that allows users to |
| 37 | +get the full browser functionality (even run extensions). Between versions 96 to 108 it was |
| 38 | +`--headless=chrome`, after version 109 `--headless=new`. |
| 39 | + |
| 40 | +Using `--headless=new` should bring a better experience when using headless with Selenium. |
| 41 | + |
| 42 | +Thanks to [Michael Mintz](https://github.com/mdmintz) for the detailed |
| 43 | +[explanation](https://stackoverflow.com/questions/45631715/downloading-with-chrome-headless-and-selenium/73840130#73840130)! |
| 44 | + |
| 45 | + |
| 46 | +### How can I set headless mode from now on? |
| 47 | + |
| 48 | +In short, users can add the headless mode they want to use through arguments in browser options. |
| 49 | + |
| 50 | +#### Before |
| 51 | +{{< tabpane langEqualsHeader=true >}} |
| 52 | +{{< tab header="Java" >}} |
| 53 | +ChromeOptions options = new ChromeOptions(); |
| 54 | +options.setHeadless(true); |
| 55 | +WebDriver driver = new ChromeDriver(options); |
| 56 | +driver.get("https://selenium.dev"); |
| 57 | +driver.quit(); |
| 58 | +{{< /tab >}} |
| 59 | +{{< tab header="JavaScript" >}} |
| 60 | +let driver = await env |
| 61 | + .builder() |
| 62 | + .setChromeOptions(new chrome.Options().headless()) |
| 63 | + .build(); |
| 64 | +await driver.get('https://selenium.dev'); |
| 65 | +await driver.quit(); |
| 66 | +{{< /tab >}} |
| 67 | +{{< tab header="CSharp" >}} |
| 68 | +// C# did not have a convenience method |
| 69 | +{{< /tab >}} |
| 70 | +{{< tab header="Ruby" >}} |
| 71 | +options = Selenium::WebDriver::Chrome::Options.new |
| 72 | +options.headless! |
| 73 | +driver = Selenium::WebDriver.for :chrome, options: options |
| 74 | +driver.get('https://selenium.dev') |
| 75 | +driver.quit |
| 76 | +{{< /tab >}} |
| 77 | +{{< tab header="Python" >}} |
| 78 | +options = ChromeOptions() |
| 79 | +options.headless = True |
| 80 | +driver = webdriver.Chrome(options=options) |
| 81 | +driver.get('http://selenium.dev') |
| 82 | +driver.quit() |
| 83 | +{{< /tab >}} |
| 84 | +{{< /tabpane >}} |
| 85 | + |
| 86 | +#### After |
| 87 | +{{< tabpane langEqualsHeader=true >}} |
| 88 | +{{< tab header="Java" >}} |
| 89 | +ChromeOptions options = new ChromeOptions(); |
| 90 | +options.addArguments("--headless=new"); |
| 91 | +WebDriver driver = new ChromeDriver(options); |
| 92 | +driver.get("https://selenium.dev); |
| 93 | +driver.quit(); |
| 94 | +{{< /tab >}} |
| 95 | +{{< tab header="JavaScript" >}} |
| 96 | +let driver = await env |
| 97 | + .builder() |
| 98 | + .setChromeOptions(options.addArguments('--headless=new')) |
| 99 | + .build(); |
| 100 | +await driver.get('https://selenium.dev'); |
| 101 | +await driver.quit(); |
| 102 | +{{< /tab >}} |
| 103 | +{{< tab header="CSharp" >}} |
| 104 | +var options = new ChromeOptions(); |
| 105 | +options.AddArgument("--headless=new"); |
| 106 | +var driver = new ChromeDriver(options); |
| 107 | +driver.Navigate().GoToUrl("https://selenium.dev"); |
| 108 | +driver.Quit(); |
| 109 | +{{< /tab >}} |
| 110 | +{{< tab header="Ruby" >}} |
| 111 | +options = Selenium::WebDriver::Options.chrome(args: ['--headless=new']) |
| 112 | +driver = Selenium::WebDriver.for :chrome, options: options |
| 113 | +driver.get('https://selenium.dev') |
| 114 | +driver.quit |
| 115 | +{{< /tab >}} |
| 116 | +{{< tab header="Python" >}} |
| 117 | +options = ChromeOptions() |
| 118 | +options.add_argument("--headless=new") |
| 119 | +driver = webdriver.Chrome(options=options) |
| 120 | +driver.get('http://selenium.dev') |
| 121 | +driver.quit() |
| 122 | +{{< /tab >}} |
| 123 | +{{< /tabpane >}} |
| 124 | + |
| 125 | + |
| 126 | +If you have any questions or comments, please reach out through any of all the available options |
| 127 | +shown at our [support page](https://www.selenium.dev/support/). |
| 128 | + |
| 129 | +Stay tuned for updates by following [SeleniumHQ](https://twitter.com/seleniumhq)! |
| 130 | + |
| 131 | +Happy testing! |
0 commit comments