Set Firefox profile
Set a custom Firefox profile or use an existing profile for your tests that run on Firefox browsers in BrowserStack Automate.
Firefox profiles include custom preferences that you would like to simulate an environment for your test script. For example, you might want to create a profile that sets preferences to handle the download popup programmatically during your test run.
The following sections include sample code snippets to create a profile or use an existing profile with preferences that handle the download popup and succesfully downloads the file.
Check out the available preferences at the MozillaZine Knowledge Base.
In this guide, you will learn about:
Create a custom Firefox profile
Use the following sample code snippets to create a custom profile.
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.HashMap;
public class JavaSample {
public static final String URL = "https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 1);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
// You will need to find the content-type of your app and set it here.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("browserName", "Firefox");
capabilities.setCapability("browserVersion", "95.0");
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("os", "OS X");
browserstackOptions.put("osVersion", "Monterey");
browserstackOptions.put("buildName", "Selenium Java Firefox Profile");
browserstackOptions.put("sessionName", "Selenium Java Firefox Profile");
browserstackOptions.put("userName", "YOUR_USERNAME");
browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY");
capabilities.setCapability("bstack:options", browserstackOptions);
capabilities.setProfile(profile);
WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities);
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices");
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView();", driver.findElement(By.className("icon-csv")));
jse.executeScript("window.scrollBy(0,-100)");
Thread.sleep(2000);
WebElement element = driver.findElement(By.className("icon-csv"));
element.click();
Thread.sleep(2000);
jse.executeScript("browserstack_executor: {\"action\": \"fileExists\"}");
jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.quit();
}
}
const {
Builder,
By,
Key,
until
} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox')
const fs = require("fs");
const webdriver = require('selenium-webdriver');
const bb = require('bluebird');
const sleep = require('util').promisify(setTimeout);
let profile = new firefox.Options();
profile.setPreference('browser.download.folderList', 1);
profile.setPreference('browser.download.manager.showWhenStarting', false);
profile.setPreference('browser.download.manager.focusWhenStarting', false);
profile.setPreference('browser.download.useDownloadDir', true);
profile.setPreference('browser.helperApps.alwaysAsk.force', false);
profile.setPreference('browser.download.manager.alertOnEXEOpen', false);
profile.setPreference('browser.download.manager.closeWhenDone', true);
profile.setPreference('browser.download.manager.showAlertOnComplete', false);
profile.setPreference('browser.download.manager.useWindow', false);
profile.setPreference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream');
let capabilities = {
'browserName' : 'firefox',
'browserVersion' : 'latest',
'bstack:options' : {
'os' : 'OS X',
'osVersion' : 'Monterey',
'userName': 'YOUR_USERNAME',
'accessKey': 'YOUR_ACCESS_KEY',
'buildName': 'Selenium NodeJS Firefox Profile',
'sessionName': 'Selenium NodeJS Firefox Profile'
}
}
const runTestWithCaps = async (capabilities) => {
let driver;
try {
driver = new webdriver.Builder().
usingServer('https://hub-cloud.browserstack.com/wd/hub').
setFirefoxOptions(profile).
withCapabilities(capabilities).
build();
await driver.get('https://www.browserstack.com/test-on-the-right-mobile-devices');
const element = await driver.findElement(By.className('icon-csv'));
await driver.executeScript('arguments[0].scrollIntoView();', element);
await driver.executeScript('window.scrollBy(0,-200)');
await driver.findElement(By.id("accept-cookie-notification")).click()
await element.click();
await sleep(5000);
await driver.executeScript("browserstack_executor: {\"action\": \"fileExists\"}");
await driver.executeScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
} catch (e) {
console.log('Error ', e)
} finally {
// await sleep(60000)
await driver.quit();
}
}
// runTestWithCaps({'browserName': 'firefox'});
runTestWithCaps(capabilities);
using System.Collections.Generic;
using System.Threading;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.IO;
using System;
using System.Text;
namespace SeleniumTest
{
class Program
{
public static void Main(string[] args)
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("browser.download.showWhenStarting", false);
firefoxProfile.SetPreference("browser.download.folderList", 1);
firefoxProfile.SetPreference("browser.download.manager.focusWhenStarting", false);
firefoxProfile.SetPreference("browser.download.useDownloadDir", true);
firefoxProfile.SetPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
firefoxProfile.SetPreference("browser.download.manager.closeWhenDone", true);
firefoxProfile.SetPreference("browser.download.manager.showAlertOnComplete", false);
firefoxProfile.SetPreference("browser.download.manager.useWindow", false);
firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
FirefoxOptions capabilities = new FirefoxOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("os", "OS X");
browserstackOptions.Add("osVersion", "catalina");
browserstackOptions.Add("useW3C", "true");
browserstackOptions.Add("buildName", "Selenium C# Firefox Profile");
browserstackOptions.Add("userName", "YOUR_USERNAME");
browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
capabilities.Profile = firefoxProfile;
RemoteWebDriver driver = new RemoteWebDriver(
new Uri("https://hub-cloud.browserstack.com/wd/hub"), capabilities
);
// Navigate to the link
driver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
Thread.Sleep(2000);
// This will scroll the page till the element is found
driver.ExecuteScript("arguments[0].scrollIntoView();", driver.FindElementByClassName("icon-csv"));
driver.ExecuteScript("window.scrollBy(0,-100)");
Thread.Sleep(2000);
// Find element by class name and then click"
driver.FindElementByClassName("icon-csv").Click();
Thread.Sleep(1000);
driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\"}");
driver.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.Quit();
}
}
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
from selenium.webdriver.firefox.options import Options as FirefoxOptions
options = FirefoxOptions()
options.set_preference('browser.download.folderList', 1)
options.set_preference('browser.download.manager.showWhenStarting', False)
options.set_preference('browser.download.manager.focusWhenStarting', False)
options.set_preference('browser.download.useDownloadDir', True)
options.set_preference('browser.helperApps.alwaysAsk.force', False)
options.set_preference('browser.download.manager.alertOnEXEOpen', False)
options.set_preference('browser.download.manager.closeWhenDone', True)
options.set_preference('browser.download.manager.showAlertOnComplete', False)
options.set_preference('browser.download.manager.useWindow', False)
# You will need to find the content-type of your app and set it here. We are downloading a gzip file.
options.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
# options.update_preferences()
caps = {
"os" : "OS X",
"osVersion" : "Catalina",
"buildName" : "firefoxprofile- node",
"sessionName" : "firefoxprofile- node",
"local" : "false",
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
}
options.set_capability('bstack:options', caps)
options.set_capability('browserVersion', '95')
options.set_capability('browserName', 'Firefox')
driver = webdriver.Remote(
command_executor='https://hub.browserstack.com/wd/hub',
options=options)
# Navigate to the link
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices")
# Accept the cookie popup
test=driver.find_element_by_id("accept-cookie-notification").click()
time.sleep(2)
# Find element by class name and store in variable "element"
element = driver.find_element_by_class_name("icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
time.sleep(2)
# Click on the element to download the file
clicked = element.click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'selenium-webdriver'
# Input capabilities
options = Selenium::WebDriver::Firefox::Options.new
options.add_preference('browser.download.folderList', 1)
options.add_preference('browser.download.manager.showWhenStarting', false)
options.add_preference('browser.download.manager.showWhenStarting', false)
options.add_preference('browser.download.useDownloadDir', true)
options.add_preference('browser.helperApps.alwaysAsk.force', false)
options.add_preference('browser.download.manager.alertOnEXEOpen', false)
options.add_preference('browser.download.manager.closeWhenDone', true)
options.add_preference('browser.download.manager.showAlertOnComplete', true)
options.add_preference('browser.download.manager.useWindow', false)
# You will need to find the content-type of your app and set it here.
options.add_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
options.browser_version = '95'
bstack_options = {
"os" => "OS X",
"osVersion" => "Sierra",
"buildName" => "Final-Snippet-Test",
"sessionName" => "Selenium-4 Ruby snippet test",
"userName" => "YOUR_USERNAME",
"accessKey" => "YOUR_ACCESS_KEY",
}
options.add_option('bstack:options', bstack_options)
driver = Selenium::WebDriver.for(:remote,
:url => "https://hub-cloud.browserstack.com/wd/hub",
:capabilities => options)
driver.navigate.to "https://www.browserstack.com/test-on-the-right-mobile-devices"
test = driver.find_element(id:"accept-cookie-notification").click
sleep(4)
element = driver.find_element(class:"icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
sleep(2)
clicked = element.click()
sleep(2)
driver.quit
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.ClickAction;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.firefox.*;
import java.net.URL;
public class JavaSample {
public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 1);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
// You will need to find the content-type of your app and set it here.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("browser", "Firefox");
capabilities.setCapability("browser_version", "latest");
capabilities.setCapability("os", "Windows");
capabilities.setCapability("os_version", "10");
capabilities.setCapability("build", "Selenium Java Firefox Profile");
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setProfile(profile);
WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities);
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices");
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView();", driver.findElement(By.className("icon-csv")));
jse.executeScript("window.scrollBy(0,-100)");
Thread.sleep(2000);
WebElement element = driver.findElement(By.className("icon-csv"));
element.click();
Thread.sleep(2000);
jse.executeScript("browserstack_executor: {\"action\": \"fileExists\"}");
jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.quit();
}
}
const {
Builder,
By,
Key,
until
} = require('selenium-webdriver');
const fs = require("fs");
const webdriver = require('selenium-webdriver');
const bb = require('bluebird');
var sleep = require('sleep');
var FirefoxProfile = require('firefox-profile');
var profile = new FirefoxProfile();
profile.setPreference('browser.download.folderList', 1);
profile.setPreference('browser.download.manager.showWhenStarting', false);
profile.setPreference('browser.download.manager.focusWhenStarting', false);
profile.setPreference('browser.download.useDownloadDir', true);
profile.setPreference('browser.helperApps.alwaysAsk.force', false);
profile.setPreference('browser.download.manager.alertOnEXEOpen', false);
profile.setPreference('browser.download.manager.closeWhenDone', true);
profile.setPreference('browser.download.manager.showAlertOnComplete', false);
profile.setPreference('browser.download.manager.useWindow', false);
// You will need the content-type of your app from developer tools on your browser and set it here. We are downloading a csv file.
profile.setPreference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream');
profile.updatePreferences();
profile.encode((err, encoded) => {
let capabilities = {
'browserName': 'firefox',
'browser_version': 'latest',
'os': 'Windows',
'os_version': '10',
'browserstack.user': 'YOUR_USERNAME',
'browserstack.key': 'YOUR_ACCESS_KEY',
'build': 'Selenium NodeJS Firefox Profile',
'firefox_profile': encoded
}
var driver = new webdriver.Builder().
usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();
// Navigate to the link
driver.get('https://www.browserstack.com/test-on-the-right-mobile-devices').then(function() {
// Find element by class name and store in variable "element"
driver.findElement(By.className('icon-csv')).then(function(element) {
// This will scroll the page till the element is found
driver.executeScript('arguments[0].scrollIntoView();', element).then(function() {
driver.executeScript('window.scrollBy(0,-200)').then(function() {
// Accept the cookie popup
driver.findElement(By.id("accept-cookie-notification")).click().then(function() {
// Click on the element to download the file
element.click().then(function() {
bb.delay(5000).then(function() {
driver.quit();
});
});
});
});
});
});
});
});
using System.Collections.Generic;
using System.Threading;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.IO;
using System;
using System.Text;
namespace SeleniumTest
{
class Program
{
public static void Main(string[] args)
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("browser.download.showWhenStarting", false);
firefoxProfile.SetPreference("browser.download.folderList", 1);
firefoxProfile.SetPreference("browser.download.manager.focusWhenStarting", false);
firefoxProfile.SetPreference("browser.download.useDownloadDir", true);
firefoxProfile.SetPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
firefoxProfile.SetPreference("browser.download.manager.closeWhenDone", true);
firefoxProfile.SetPreference("browser.download.manager.showAlertOnComplete", false);
firefoxProfile.SetPreference("browser.download.manager.useWindow", false);
firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.AddAdditionalCapability("os", "os x", true);
capabilities.AddAdditionalCapability("os_version", "monterey", true);
capabilities.AddAdditionalCapability("build", "Firefox Profile C# Selenium3", true);
capabilities.AddAdditionalCapability("browser", "firefox", true);
capabilities.AddAdditionalCapability("browser_version", "latest", true);
capabilities.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true);
capabilities.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true);
capabilities.Profile = firefoxProfile;
RemoteWebDriver driver = new RemoteWebDriver(
new Uri("https://hub-cloud.browserstack.com/wd/hub"), capabilities
);
// Navigate to the link
driver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
Thread.Sleep(2000);
// This will scroll the page till the element is found
driver.ExecuteScript("arguments[0].scrollIntoView();", driver.FindElementByClassName("icon-csv"));
driver.ExecuteScript("window.scrollBy(0,-100)");
Thread.Sleep(2000);
// Find element by class name and then click"
driver.FindElementByClassName("icon-csv").Click();
Thread.Sleep(1000);
driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\"}");
driver.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.Quit();
}
}
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 1)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.manager.focusWhenStarting', False)
profile.set_preference('browser.download.useDownloadDir', True)
profile.set_preference('browser.helperApps.alwaysAsk.force', False)
profile.set_preference('browser.download.manager.alertOnEXEOpen', False)
profile.set_preference('browser.download.manager.closeWhenDone', True)
profile.set_preference('browser.download.manager.showAlertOnComplete', False)
profile.set_preference('browser.download.manager.useWindow', False)
# You will need to find the content-type of your app and set it here. We are downloading a gzip file.
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
profile.update_preferences()
desired_cap = {
'browser': 'Firefox',
'browser_version': 'latest',
'os': 'OS X',
'os_version': 'Monetery',
'build': 'Selenium Python Firefox Profile'
}
driver = webdriver.Remote(
command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub',
desired_capabilities=desired_cap, browser_profile=profile)
# Navigate to the link
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices")
# Accept the cookie popup
test=driver.find_element_by_id("accept-cookie-notification").click()
time.sleep(2)
# Find element by class name and store in variable "element"
element = driver.find_element_by_class_name("icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
time.sleep(2)
# Click on the element to download the file
clicked = element.click()
time.sleep(2)
driver.execute_script("browserstack_executor: {\"action\": \"fileExists\"}")
driver.execute_script("browserstack_executor: {\"action\": \"getFileProperties\"}")
driver.quit()
require 'rubygems'
require 'selenium-webdriver'
# Input capabilities
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 1
profile['browser.download.manager.showWhenStarting'] = false
profile['browser.download.manager.focusWhenStarting'] = false
profile['browser.download.useDownloadDir'] = true
profile['browser.helperApps.alwaysAsk.force'] = false
profile['browser.download.manager.alertOnEXEOpen'] = false
profile['browser.download.manager.closeWhenDone'] = true
profile['browser.download.manager.showAlertOnComplete'] = false
profile['browser.download.manager.useWindow'] = false
# You will need to find the content-type of your app and set it here.
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/octet-stream"
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:options => profile)
caps['browser'] = 'Firefox'
caps['browser_version'] = 'latest'
caps['os'] = 'OS X'
caps['os_version'] = 'Monterey'
caps['name'] = 'Bstack-[Ruby] Sample file download'
caps["javascriptEnabled"] = "true"
driver = Selenium::WebDriver.for(:remote,
:url => "https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",
:desired_capabilities => caps)
driver.navigate.to "https://www.browserstack.com/test-on-the-right-mobile-devices"
test = driver.find_element(id:"accept-cookie-notification").click
sleep(4)
element = driver.find_element(class:"icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
sleep(2)
clicked = element.click()
sleep(2)
# driver.find_element(:id => 'download').click
driver.quit
Use an existing Firefox profile
Using an existing profile from your local machine involves the following steps:
Create the Firefox profile locally
- In the Firefox browser, enter
about:profiles
in the address bar. - Create a new profile and click Launch profile in new browser.
- Enter
about:config
in the address bar - Search for the following preferences in the search bar. If a preference is not autopopulated, you can add it manually.
-
browser.download.showWhenStarting
tofalse
-
browser.download.folderList
to1
-
browser.download.manager.focusWhenStarting
tofalse
-
browser.download.useDownloadDir
totrue
-
browser.helperApps.alwaysAsk.force
tofalse
-
browser.download.manager.alertOnEXEOpen
tofalse
-
browser.download.manager.closeWhenDone
totrue
-
browser.download.manager.showAlertOnComplete
tofalse
-
browser.download.manager.useWindow
tofalse
-
browser.helperApps.neverAsk.saveToDisk
toapplication/octet-stream
-
Check out the official Mozilla documentation for detailed information.
Setting the Firefox profile in test scripts
Use the following sample code snippets to use an existing Firefox profile.
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.HashMap;
public class JavaSample {
public static final String URL = "https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("profile", "/Users/test/Library/Application Support/Firefox/Profiles/x0w613zr.firefox_profile");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("browserName", "Firefox");
capabilities.setCapability("browserVersion", "95.0");
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("os", "OS X");
browserstackOptions.put("osVersion", "Monterey");
browserstackOptions.put("buildName", "Selenium Java Firefox Profile");
browserstackOptions.put("sessionName", "Selenium Java Firefox Profile");
capabilities.setCapability("bstack:options", browserstackOptions);
capabilities.setProfile(profile);
WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities);
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices");
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView();", driver.findElement(By.className("icon-csv")));
jse.executeScript("window.scrollBy(0,-100)");
Thread.sleep(2000);
WebElement element = driver.findElement(By.className("icon-csv"));
element.click();
Thread.sleep(2000);
jse.executeScript("browserstack_executor: {\"action\": \"fileExists\"}");
jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.quit();
}
}
const {
Builder,
By,
Key,
until
} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox')
const fs = require("fs");
const webdriver = require('selenium-webdriver');
const bb = require('bluebird');
const sleep = require('util').promisify(setTimeout);
let options = new firefox.Options('/Users/test/Library/Application Support/Firefox/Profiles/x0w613zr.firefox_profile');
let capabilities = {
'browserName' : 'firefox',
'browserVersion' : 'latest',
'bstack:options' : {
'os' : 'OS X',
'osVersion' : 'Monterey',
'userName': 'YOUR_USERNAME',
'accessKey': 'YOUR_ACCESS_KEY',
'buildName': 'Selenium NodeJS Firefox Profile',
'sessionName': 'Selenium NodeJS Firefox Profile'
}
}
const runTestWithCaps = async (capabilities) => {
let driver;
try {
driver = new webdriver.Builder().
usingServer('https://hub-cloud.browserstack.com/wd/hub').
setFirefoxOptions(options).
withCapabilities(capabilities).
build();
await driver.get('https://www.browserstack.com/test-on-the-right-mobile-devices');
const element = await driver.findElement(By.className('icon-csv'));
await driver.executeScript('arguments[0].scrollIntoView();', element);
await driver.executeScript('window.scrollBy(0,-200)');
await driver.findElement(By.id("accept-cookie-notification")).click()
await element.click();
await sleep(5000);
await driver.executeScript("browserstack_executor: {\"action\": \"fileExists\"}");
await driver.executeScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
} catch (e) {
console.log('Error ', e)
} finally {
// await sleep(60000)
await driver.quit();
}
}
// runTestWithCaps({'browserName': 'firefox'});
runTestWithCaps(capabilities);
using System.Collections.Generic;
using System.Threading;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.IO;
using System;
using System.Text;
namespace SeleniumTest
{
class Program
{
public static void Main(string[] args)
{
FirefoxProfile firefoxProfile = new FirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");
FirefoxOptions capabilities = new FirefoxOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("os", "OS X");
browserstackOptions.Add("osVersion", "catalina");
browserstackOptions.Add("useW3C", "true");
browserstackOptions.Add("buildName", "Selenium C# Firefox Profile");
browserstackOptions.Add("userName", "YOUR_USERNAME");
browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
capabilities.Profile = firefoxProfile;
RemoteWebDriver driver = new RemoteWebDriver(
new Uri("https://hub-cloud.browserstack.com/wd/hub"), capabilities
);
// Navigate to the link
driver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
Thread.Sleep(2000);
// This will scroll the page till the element is found
driver.ExecuteScript("arguments[0].scrollIntoView();", driver.FindElementByClassName("icon-csv"));
driver.ExecuteScript("window.scrollBy(0,-100)");
Thread.Sleep(2000);
// Find element by class name and then click"
driver.FindElementByClassName("icon-csv").Click();
Thread.Sleep(1000);
driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\"}");
driver.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.Quit();
}
}
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
options = webdriver.FirefoxOptions()
options.set_preference('profile', "/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>")
caps = {
"os" : "OS X",
"osVersion" : "Monterey",
"buildName" : "firefoxprofile- python",
"sessionName" : "firefoxprofile- python",
"browserName" : "Firefox",
}
options.set_capability('bstack:options', caps)
driver = webdriver.Remote(
command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub',
options=options)
# Navigate to the link
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices")
# Accept the cookie popup
test=driver.find_element_by_id("accept-cookie-notification").click()
time.sleep(2)
# Find element by class name and store in variable "element"
element = driver.find_element_by_class_name("icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
time.sleep(2)
# Click on the element to download the file
clicked = element.click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'selenium-webdriver'
# Input capabilities
profile = Selenium::WebDriver::Firefox::Profile.new("/Users/test/Library/Application Support/Firefox/Profiles/x0w613zr.firefox_profile")
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
options.browser_version = '97'
bstack_options = {
"os" => "OS X",
"osVersion" => "Catalina",
"buildName" => "Final-Snippet-Test",
"sessionName" => "Selenium-4 Ruby snippet test",
"userName" => "YOUR_USERNAME",
"accessKey" => "YOUR_ACCESS_KEY",
}
options.add_option('bstack:options', bstack_options)
driver = Selenium::WebDriver.for(:remote,
:url => "https://hub-cloud.browserstack.com/wd/hub",
:capabilities => options)
driver.navigate.to "https://www.browserstack.com/test-on-the-right-mobile-devices"
test = driver.find_element(id:"accept-cookie-notification").click
sleep(4)
element = driver.find_element(class:"icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
sleep(2)
clicked = element.click()
sleep(2)
driver.quit
const {
Builder,
By,
Key,
until
} = require('selenium-webdriver');
const fs = require("fs");
const webdriver = require('selenium-webdriver');
const bb = require('bluebird');
var sleep = require('sleep');
var FirefoxProfile = require('firefox-profile');
var profile = new FirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");
profile.updatePreferences();
profile.encode((err, encoded) => {
let capabilities = {
'browserName': 'firefox',
'browser_version': 'latest',
'os': 'OS X',
'os_version': 'Monterey',
'browserstack.user': 'YOUR_USERNAME',
'browserstack.key': 'YOUR_ACCESS_KEY',
'build': 'Selenium NodeJS Firefox Profile',
'firefox_profile': encoded
}
var driver = new webdriver.Builder().
usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();
// Navigate to the link
driver.get('https://www.browserstack.com/test-on-the-right-mobile-devices').then(function() {
// Find element by class name and store in variable "element"
driver.findElement(By.className('icon-csv')).then(function(element) {
// This will scroll the page till the element is found
driver.executeScript('arguments[0].scrollIntoView();', element).then(function() {
driver.executeScript('window.scrollBy(0,-200)').then(function() {
// Accept the cookie popup
driver.findElement(By.id("accept-cookie-notification")).click().then(function() {
// Click on the element to download the file
element.click().then(function() {
bb.delay(5000).then(function() {
driver.quit();
});
});
});
});
});
});
});
});
using System.Collections.Generic;
using System.Threading;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.IO;
using System;
using System.Text;
namespace SeleniumTest
{
class Program
{
public static void Main(string[] args)
{
FirefoxProfile firefoxProfile = new FirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.AddAdditionalCapability("os", "os x", true);
capabilities.AddAdditionalCapability("os_version", "monterey", true);
capabilities.AddAdditionalCapability("build", "Firefox Profile C# Selenium3", true);
capabilities.AddAdditionalCapability("browser", "firefox", true);
capabilities.AddAdditionalCapability("browser_version", "latest", true);
capabilities.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true);
capabilities.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true);
capabilities.Profile = firefoxProfile;
RemoteWebDriver driver = new RemoteWebDriver(
new Uri("https://hub-cloud.browserstack.com/wd/hub"), capabilities
);
// Navigate to the link
driver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
Thread.Sleep(2000);
// This will scroll the page till the element is found
driver.ExecuteScript("arguments[0].scrollIntoView();", driver.FindElementByClassName("icon-csv"));
driver.ExecuteScript("window.scrollBy(0,-100)");
Thread.Sleep(2000);
// Find element by class name and then click"
driver.FindElementByClassName("icon-csv").Click();
Thread.Sleep(1000);
driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\"}");
driver.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\"}");
driver.Quit();
}
}
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
profile = webdriver.FirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>")
profile.update_preferences()
desired_cap = {
'browser': 'Firefox',
'browser_version': 'latest',
'os': 'OS X',
'os_version': 'Monetery',
'build': 'Selenium Python Firefox Profile'
}
driver = webdriver.Remote(
command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub',
desired_capabilities=desired_cap, browser_profile=profile)
# Navigate to the link
driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices")
# Accept the cookie popup
test=driver.find_element_by_id("accept-cookie-notification").click()
time.sleep(2)
# Find element by class name and store in variable "element"
element = driver.find_element_by_class_name("icon-csv")
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("window.scrollBy(0,-100)")
time.sleep(2)
# Click on the element to download the file
clicked = element.click()
time.sleep(2)
driver.execute_script("browserstack_executor: {\"action\": \"fileExists\"}")
driver.execute_script("browserstack_executor: {\"action\": \"getFileProperties\"}")
driver.quit()
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!