Skip to main content

Firefox Profile

With Selenium WebDriver, it's possible to set a custom Firefox profile, which will be used during your automated tests on TestingBot.
To change preferences and settings within Firefox, you'll need to instantiate a new FirefoxProfile object and update the properties of the profile.

Change Firefox Profile

In the example below, we'll set the accept language to Spanish and change the user-agent header.

require "rubygems"
require "selenium-webdriver"

profile = Selenium::WebDriver::Firefox::Profile.new
profile["general.useragent.override"] = "Custom-Agent"  # Change user-agent
profile["intl.accept_languages"] = "es"  # Setting accept language to Spanish

options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
options.browser_version = "latest"
options.platform_name = "WIN10"
options.add_option('tb:options', {
  'key' => 'API_KEY',
  'secret' => 'API_SECRET',
  'name' => 'firefox profile example'
})

driver = Selenium::WebDriver.for(:remote,
  :url => "https://hub.testingbot.com/wd/hub",
  :options => options)
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "Custom-Agent");  // Change user-agent
profile.setPreference("intl.accept_languages", "es");  // Setting accept language to Spanish
options.setProfile(profile);
options.setPlatformName("WIN10");
options.setBrowserVersion("latest");

HashMap<String, Object> tbOptions = new HashMap<>();
tbOptions.put("key", "API_KEY");
tbOptions.put("secret", "API_SECRET");
tbOptions.put("name", "firefox profile example");
options.setCapability("tb:options", tbOptions);

WebDriver driver = new RemoteWebDriver(new URL("https://hub.testingbot.com/wd/hub"), options);
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Firefox\FirefoxOptions;
use Facebook\WebDriver\Firefox\FirefoxProfile;

$profile = new FirefoxProfile();
$profile->setPreference('general.useragent.override', 'Custom-Agent');  // Change user-agent
$profile->setPreference('intl.accept_languages', 'es');  // Setting accept language to Spanish

$options = new FirefoxOptions();
$options->setProfile($profile);

$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(FirefoxOptions::CAPABILITY, $options);
$capabilities->setCapability('browserVersion', 'latest');
$capabilities->setCapability('platformName', 'WIN10');
$capabilities->setCapability('tb:options', [
  'key' => 'API_KEY',
  'secret' => 'API_SECRET',
  'name' => 'firefox profile example'
]);

$web_driver = RemoteWebDriver::create(
  "https://hub.testingbot.com/wd/hub",
  $capabilities
);
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

profile = webdriver.FirefoxProfile()
profile.set_preference('general.useragent.override', 'Custom-Agent')  # Change user-agent
profile.set_preference('intl.accept_languages', 'es')  # Setting accept language to Spanish
profile.update_preferences()

options = Options()
options.profile = profile
options.browser_version = 'latest'
options.platform_name = 'WIN10'
options.set_capability('tb:options', {
  'key': 'API_KEY',
  'secret': 'API_SECRET',
  'name': 'firefox profile example'
})

driver = webdriver.Remote(
  command_executor='https://hub.testingbot.com/wd/hub',
  options=options
)
const { Builder } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

async function main() {
  let options = new firefox.Options();
  options.setPreference('general.useragent.override', 'Custom-Agent');  // Change user-agent
  options.setPreference('intl.accept_languages', 'es');  // Setting accept language to Spanish
  options.setBrowserVersion('latest');
  options.setPlatformName('WIN10');
  options.set('tb:options', {
    'key': 'API_KEY',
    'secret': 'API_SECRET',
    'name': 'firefox profile example'
  });

  let driver = await new Builder()
    .usingServer('https://hub.testingbot.com/wd/hub')
    .setFirefoxOptions(options)
    .build();
}
main();
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("general.useragent.override", "Custom-Agent");  // Change user-agent
profile.SetPreference("intl.accept_languages", "es");  // Setting accept language to Spanish

FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
options.BrowserVersion = "latest";
options.PlatformName = "WIN10";
options.AddAdditionalOption("tb:options", new Dictionary<string, object>
{
    ["key"] = "API_KEY",
    ["secret"] = "API_SECRET",
    ["name"] = "firefox profile example"
});

IWebDriver driver = new RemoteWebDriver(
  new Uri("https://hub.testingbot.com/wd/hub"), options
);
Was this page helpful?

Looking for More Help?

Have questions or need more information?
You can reach us via the following channels: