Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
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 successfully downloads the file.
importorg.openqa.selenium.By;importorg.openqa.selenium.JavascriptExecutor;importorg.openqa.selenium.Platform;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.firefox.FirefoxProfile;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.firefox.FirefoxOptions;importorg.openqa.selenium.remote.DesiredCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importjava.net.URL;importjava.util.HashMap;publicclassJavaSample{publicstaticfinalStringURL="https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[]args)throwsException{FirefoxProfileprofile=newFirefoxProfile();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");FirefoxOptionscapabilities=newFirefoxOptions();capabilities.setCapability("browserName","Firefox");capabilities.setCapability("browserVersion","95.0");HashMap<String,Object>browserstackOptions=newHashMap<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);WebDriverdriver=newRemoteWebDriver(newURL(URL),capabilities);driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices");JavascriptExecutorjse=(JavascriptExecutor)driver;jse.executeScript("arguments[0].scrollIntoView();",driver.findElement(By.className("icon-csv")));jse.executeScript("window.scrollBy(0,-100)");Thread.sleep(2000);WebElementelement=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();}}
usingSystem.Collections.Generic;usingSystem.Threading;usingOpenQA.Selenium.Firefox;usingOpenQA.Selenium.Remote;usingOpenQA.Selenium;usingSystem.IO;usingSystem;usingSystem.Text;namespaceSeleniumTest{classProgram{publicstaticvoidMain(string[]args){FirefoxProfilefirefoxProfile=newFirefoxProfile();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");FirefoxOptionscapabilities=newFirefoxOptions();Dictionary<string,object>browserstackOptions=newDictionary<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;RemoteWebDriverdriver=newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub"),capabilities);// Navigate to the linkdriver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");IJavaScriptExecutorjse=(IJavaScriptExecutor)driver;Thread.Sleep(2000);// This will scroll the page till the element is founddriver.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();}}}
fromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesimporttimefromselenium.webdriver.firefox.optionsimportOptionsasFirefoxOptionsoptions=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 capabilitiesoptions=Selenium::WebDriver::Firefox::Options.newoptions.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").clicksleep(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
importorg.openqa.selenium.By;importorg.openqa.selenium.JavascriptExecutor;importorg.openqa.selenium.Platform;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.firefox.FirefoxProfile;importorg.openqa.selenium.interactions.ClickAction;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.remote.DesiredCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importorg.openqa.selenium.firefox.*;importjava.net.URL;publicclassJavaSample{publicstaticfinalStringAUTOMATE_USERNAME="YOUR_USERNAME";publicstaticfinalStringAUTOMATE_KEY="YOUR_ACCESS_KEY";publicstaticfinalStringURL="https://"+AUTOMATE_USERNAME+":"+AUTOMATE_KEY+"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[]args)throwsException{FirefoxProfileprofile=newFirefoxProfile();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");FirefoxOptionscapabilities=newFirefoxOptions();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);WebDriverdriver=newRemoteWebDriver(newURL(URL),capabilities);driver.get("https://www.browserstack.com/test-on-the-right-mobile-devices");JavascriptExecutorjse=(JavascriptExecutor)driver;jse.executeScript("arguments[0].scrollIntoView();",driver.findElement(By.className("icon-csv")));jse.executeScript("window.scrollBy(0,-100)");Thread.sleep(2000);WebElementelement=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');constfs=require("fs");constwebdriver=require('selenium-webdriver');constbb=require('bluebird');varsleep=require('sleep');varFirefoxProfile=require('firefox-profile');varprofile=newFirefoxProfile();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)=>{letcapabilities={'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}vardriver=newwebdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();// Navigate to the linkdriver.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 popupdriver.findElement(By.id("accept-cookie-notification")).click().then(function(){// Click on the element to download the fileelement.click().then(function(){bb.delay(5000).then(function(){driver.quit();});});});});});});});});
usingSystem.Collections.Generic;usingSystem.Threading;usingOpenQA.Selenium.Firefox;usingOpenQA.Selenium.Remote;usingOpenQA.Selenium;usingSystem.IO;usingSystem;usingSystem.Text;namespaceSeleniumTest{classProgram{publicstaticvoidMain(string[]args){FirefoxProfilefirefoxProfile=newFirefoxProfile();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");FirefoxOptionscapabilities=newFirefoxOptions();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;RemoteWebDriverdriver=newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub"),capabilities);// Navigate to the linkdriver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");IJavaScriptExecutorjse=(IJavaScriptExecutor)driver;Thread.Sleep(2000);// This will scroll the page till the element is founddriver.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();}}}
fromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesimporttimeprofile=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 capabilitiesprofile=Selenium::WebDriver::Firefox::Profile.newprofile['browser.download.folderList']=1profile['browser.download.manager.showWhenStarting']=falseprofile['browser.download.manager.focusWhenStarting']=falseprofile['browser.download.useDownloadDir']=trueprofile['browser.helperApps.alwaysAsk.force']=falseprofile['browser.download.manager.alertOnEXEOpen']=falseprofile['browser.download.manager.closeWhenDone']=trueprofile['browser.download.manager.showAlertOnComplete']=falseprofile['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").clicksleep(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').clickdriver.quit
Use an existing Firefox profile
Using an existing profile from your local machine involves the following steps:
usingSystem.Collections.Generic;usingSystem.Threading;usingOpenQA.Selenium.Firefox;usingOpenQA.Selenium.Remote;usingOpenQA.Selenium;usingSystem.IO;usingSystem;usingSystem.Text;namespaceSeleniumTest{classProgram{publicstaticvoidMain(string[]args){FirefoxProfilefirefoxProfile=newFirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");FirefoxOptionscapabilities=newFirefoxOptions();Dictionary<string,object>browserstackOptions=newDictionary<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;RemoteWebDriverdriver=newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub"),capabilities);// Navigate to the linkdriver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");IJavaScriptExecutorjse=(IJavaScriptExecutor)driver;Thread.Sleep(2000);// This will scroll the page till the element is founddriver.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();}}}
fromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesimporttimeoptions=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()
const{Builder,By,Key,until}=require('selenium-webdriver');constfs=require("fs");constwebdriver=require('selenium-webdriver');constbb=require('bluebird');varsleep=require('sleep');varFirefoxProfile=require('firefox-profile');varprofile=newFirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");profile.updatePreferences();profile.encode((err,encoded)=>{letcapabilities={'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}vardriver=newwebdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();// Navigate to the linkdriver.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 popupdriver.findElement(By.id("accept-cookie-notification")).click().then(function(){// Click on the element to download the fileelement.click().then(function(){bb.delay(5000).then(function(){driver.quit();});});});});});});});});
usingSystem.Collections.Generic;usingSystem.Threading;usingOpenQA.Selenium.Firefox;usingOpenQA.Selenium.Remote;usingOpenQA.Selenium;usingSystem.IO;usingSystem;usingSystem.Text;namespaceSeleniumTest{classProgram{publicstaticvoidMain(string[]args){FirefoxProfilefirefoxProfile=newFirefoxProfile("/Users/test/Library/Application Support/Firefox/Profiles/<name_of_your_profile>");FirefoxOptionscapabilities=newFirefoxOptions();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;RemoteWebDriverdriver=newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub"),capabilities);// Navigate to the linkdriver.Navigate().GoToUrl("https://www.browserstack.com/test-on-the-right-mobile-devices");IJavaScriptExecutorjse=(IJavaScriptExecutor)driver;Thread.Sleep(2000);// This will scroll the page till the element is founddriver.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();}}}
fromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesimporttimeprofile=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()
Did this page help you?
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
Test web and mobile, from manual to automation, on real devices in one unified platform.