Selenium 4 - New Features For Firefox

Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted

February 07, 2026 · 6 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to execution in minutes.

|

x

Back to Resources

Blog

Posted October 20, 2021

Selenium 4 - New Features For Firefox

This article covers the new features in Selenium 4 that are specific to Firefox.

quote

Selenium 4 exposes a few new features that can be used with Firefox. It is easier to install/uninstall add-ons, or change the browser preferences (such as the language) in the middle of the session, or take a full page screenshot for bug coverage. Examples demo how to do that are shown below.

Install/uninstall Add-ons

Here is a test in Java that installs a Firefox add-on. For additional instance in multiple languages, check out our. This add-on, when active, swaps any image present on the site with the SauceBot Ninja. After the add-on is establish, we assert the SauceBot Ninja is present. Then, we uninstall the add-on, reload the site, and we affirm the SauceBot Ninja is gone.

1
@Test
2
public void installAddOnWithFirefoxOnSauce () throws MalformedURLException {
3
String userName = System.getenv (& quot; SAUCE_USERNAME & quot;);
4
String accessKey = System.getenv (& quot; SAUCE_ACCESS_KEY & quot;);
5
URL gridUrl = new URL (& quot; https: //ondemand.us-west-1.saucelabs.com:443/wd/hub & quot;);
6
FirefoxOptions firefoxOptions = new FirefoxOptions ();
7
firefoxOptions.setCapability (& quot; platformName & quot;, & quot; Windows 10 & quot;);
8
firefoxOptions.setCapability (& quot; browserVersion & quot;, & quot; latest & quot;);
9
10
Map & lt; String, Object & gt; sauceOptions = new HashMap & lt; & gt; ();
11
sauceOptions.put (& quot; name & quot;, & quot; installAddOnWithFirefoxOnSauce & quot;);
12
sauceOptions.put (& quot; username & quot;, userName);
13
sauceOptions.put (& quot; accessKey & quot;, accessKey);
14
firefoxOptions.setCapability (& quot; sauce: options & quot;, sauceOptions);
15
16
RemoteWebDriver driver = new RemoteWebDriver (gridUrl, firefoxOptions);
17
driver.setFileDetector (new LocalFileDetector ());
18
WebDriver augmentedDriver = new Augmenter () .augment (driver);
19
20
// Loads SauceDemo unremarkably
21
driver.get (& quot; https: //www.saucedemo.com & quot;);
22
23
// This is an propagation that switches the page images for the SauceBot Ninja
24
// Extension can be found at https: //git.io/JwUry
25
String id = ((HasExtensions) augmentedDriver)
26
.installExtension (Paths.get (& quot; src/test/resources/ninja_saucebot-1.0-an+fx.xpi & quot;));
27
// Site is loaded again
28
driver.navigate () .refresh ();
29
// We see that the SauceBot Ninja is present
30
Assertions.assertTrue (driver.findElements (By.className (& quot; bot_column2 & quot;)) .size () & gt; 0);
31
32
// Add-on is uninstalled
33
((HasExtensions) augmentedDriver) .uninstallExtension (id);
34
35
driver.navigate () .refresh ();
36
// The SauceBot Ninja is not present anymore
37
Assertions.assertEquals (0, driver.findElements (By.className (& quot; bot_column2 & quot;)) .size ());
38
39
driver.quit ();
40
}

Installing and uninstalling add-ons in Sauce Labs:

Asset > firefox add-ons

Updating Firefox Browser Preferences

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Changing Firefox browser druthers, like prove your website with different languages, is now easier with Selenium 4. This example establish you how you can update the browser words using changeBrowserPreferencesInFirefox, yet after the session has been created. Here is an example in Java; for additional representative in multiple languages, check out our.

1
@Test
2
publicvoidchangeBrowserPreferencesInFirefox() throws MalformedURLException{
3
String userName =System.getenv(& quot; SAUCE_USERNAME & quot;);
4
String accessKey =System.getenv(& quot; SAUCE_ACCESS_KEY & quot;);
5
URL gridUrl =newURL(& quot; https: //ondemand.us-west-1.saucelabs.com:443/wd/hub & quot;);
6
FirefoxOptionsfirefoxOptions=newFirefoxOptions();
7
firefoxOptions.setCapability(& quot; platformName & quot;,& quot; Windows 10 & quot;);
8
firefoxOptions.setCapability(& quot; browserVersion & quot;,& quot; latest & quot;);
9
firefoxOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
10
firefoxOptions.addPreference(& quot; intl.accept_languages & quot;,& quot; de-DE & quot;);
11
12
Map<String,Object>sauceOptions=newHashMap<>();
13
sauceOptions.put(& quot; name & quot;,& quot; changeBrowserPreferencesInFirefox & quot;);
14
sauceOptions.put(& quot; username & quot;, userName);
15
sauceOptions.put(& quot; accessKey & quot;, accessKey);
16
firefoxOptions.setCapability(& quot; sauce: options & quot;,sauceOptions);
17
18
RemoteWebDriver driver =newRemoteWebDriver(gridUrl,firefoxOptions);
19
20
driver.get(& quot; https: //www.google.com & quot;);
21
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(90));
22
23
String langDE = driver
24
.findElement(By.id(& quot; gws-output-pages-elements-homepage_additional_languages__als & quot;))
25
.getText();
26
Assertions.assertTrue(langDE.contains(& quot; angeboten auf & quot;));
27
28
WebDriveraugmentedDriver=newAugmenter().augment(driver);
29
((HasContext)augmentedDriver).setContext(FirefoxCommandContext.CHROME);
30
31
((JavascriptExecutor) driver)
32
.executeScript(& quot; Services.prefs.setStringPref (& # x27; intl.accept_languages & # x27;, & # x27; es-ES & # x27;) & quot;);
33
34
((HasContext)augmentedDriver).setContext(FirefoxCommandContext.CONTENT);
35
driver.navigate().refresh();
36
37
String langES = driver
38
.findElement(By.id(& quot; gws-output-pages-elements-homepage_additional_languages__als & quot;))
39
.getText();
40
Assertions.assertTrue(langES.contains(& quot; Ofrecido por & quot;));
41
42
driver.quit();
43
}

Testing different languages with Firefox on Sauce Labs:

Asset > changeBrowserPreferencesInFirefox

Full Page Screenshot

Screenshots with WebDriver capture the viewport. It is possible to capture the whole page now with Firefox, which could be utilitarian to add full page screenshots to bug reports, for example. Here is an example in Java; for additional examples in multiple lyric, check out our.

1
@Test
2
public void fullPageScreenshotWithFirefox () throw IOException {
3
String userName = System.getenv (& quot; SAUCE_USERNAME & quot;);
4
String accessKey = System.getenv (& quot; SAUCE_ACCESS_KEY & quot;);
5
URL gridUrl = new URL (& quot; https: //ondemand.us-west-1.saucelabs.com:443/wd/hub & quot;);
6
FirefoxOptions firefoxOptions = new FirefoxOptions ();
7
firefoxOptions.setCapability (& quot; platformName & quot;, & quot; Windows 10 & quot;);
8
firefoxOptions.setCapability (& quot; browserVersion & quot;, & quot; latest & quot;);
9
10
Map & lt; String, Object & gt; sauceOptions = new HashMap & lt; & gt; ();
11
sauceOptions.put (& quot; name & quot;, & quot; printPageWithFirefox & quot;);
12
sauceOptions.put (& quot; username & quot;, userName);
13
sauceOptions.put (& quot; accessKey & quot;, accessKey);
14
firefoxOptions.setCapability (& quot; sauce: alternative & quot;, sauceOptions);
15
16
RemoteWebDriver driver = new RemoteWebDriver (gridUrl, firefoxOptions);
17
18
driver.get (& quot; https: //www.saucedemo.com/v1/inventory.html & quot;);
19
WebDriver augmentedDriver = new Augmenter () .augment (driver);
20
File file = ((HasFullPageScreenshot) augmentedDriver)
21
.getFullPageScreenshotAs (OutputType.FILE);
22
Path fullPageScreenshot =
23
Paths.get (& quot; src/test/screenshots/fullPageScreenshotFirefox.png & quot;);
24
Files.move (file.toPath (), fullPageScreenshot);
25
26
driver.quit ();
27
}
Titus Fortner

Sr. Developer Experience Engineer, Sauce Labs

Diego Molina

Staff Software Engineer at Sauce Labs

Published:
Oct 20, 2021
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks own by Sauce Labs Inc. in the United States, EU, and may be register in former jurisdiction.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free