M HYPE SPLASH
// updates

Test file download in Selenium tests

By Emma Terry

Learn how to test the file download functionality of your web app using BrowserStack Automate

Overview

File download functionality is often implemented in web applications to support scenarios, such as downloading invoices, PDFs, etc. Though Selenium provides basic commands to download any file from a website, BrowserStack provides custom executors to assert if the file is downloaded successfully, view file properties, and transfer files to local machine.

In this guide, you will learn how to:

Download files on Browserstack remote instances

BrowserStack provides a custom browserstack_executor script that lets you check whether the file is downloaded successfully in an Automate session. The following sample code shows how to use Selenium to download a file on a Browserstack remote instance in your Automate session:

import org.openqa.selenium.By;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.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;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 + "@"; 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"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "Firefox"); capabilities.setCapability("browserVersion", "latest"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); 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) => { var capabilities = { 'bstack:options' : { "os" : "Windows", "osVersion" : "10", "userName" : "YOUR_USERNAME", "accessKey" : "YOUR_ACCESS_KEY", }, "browserName" : "Firefox", "browserVersion" : "latest", } var driver = new webdriver.Builder() .usingServer('') .withCapabilities(capabilities) .build(); // Navigate to the link driver.get('').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(); }); }); }); }); }); }); });});
// Applies to Selenium W3C protocol versionsusing 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.BrowserVersion = "latest"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("buildName", "Selenium C# Firefox Profile"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "Firefox"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); capabilities.Profile = firefoxProfile; RemoteWebDriver driver = new RemoteWebDriver( new Uri(""), capabilities ); // Navigate to the link driver.Navigate().GoToUrl(""); 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 webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesimport timeprofile = 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 = {'bstack:options' : {"os" : "Windows","osVersion" : "10",},"browserName" : "Firefox","browserVersion" : "latest",}options.set_capability('bstack:options', desired_cap)driver = webdriver.Remote( command_executor=', options=options)# Navigate to the linkdriver.get("")# Accept the cookie popuptest=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 fileclicked = element.click()time.sleep(2)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"capabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10",},"browserName" => "Firefox","browserVersion" => "latest",}driver = Selenium::WebDriver.for( :remote, :url => "", :capabilities => capabilities)driver.navigate.to ""driver.find_element(:id => 'download').clickdriver.quit
import org.openqa.selenium.By;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.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;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 + "@"; 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"); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("browser", "Firefox"); caps.setCapability("browser_version", "latest"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("name", "Bstack-[Java] Sample file download"); caps.setCapability(FirefoxDriver.PROFILE, profile); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); 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', 'name': 'Bstack-[Node] Sample file download', 'firefox_profile': encoded } var driver = new webdriver.Builder(). usingServer('').withCapabilities(capabilities).build(); // Navigate to the link driver.get('').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(); }); }); }); }); }); }); });});
// Applies to Selenium W3C protocol versionsusing 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", "BROWSERSTACK_USERNAME"); browserstackOptions.Add("accessKey", "BROWSERSTACK_ACCESS_KEY"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); capabilities.Profile = firefoxProfile; RemoteWebDriver driver = new RemoteWebDriver( new Uri(""), capabilities ); // Navigate to the link driver.Navigate().GoToUrl(""); 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 webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesimport timeprofile = 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': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor=', desired_capabilities=desired_cap, browser_profile=profile)# Navigate to the linkdriver.get("")# Accept the cookie popuptest=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 fileclicked = element.click()time.sleep(2)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"caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)caps['browser'] = 'Firefox'caps['browser_version'] = 'latest'caps['os'] = 'Windows'caps['os_version'] = '10'caps['name'] = 'Bstack-[Ruby] Sample file download'driver = Selenium::WebDriver.for(:remote, :url => "", :desired_capabilities => caps)driver.navigate.to ""driver.find_element(:id => 'download').clickdriver.quit

Test download functionality in the different browsers including Chrome, Edge, and Safari.

import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "Chrome"); capabilities.setCapability("browserVersion", "latest"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); browserstackOptions.put("projectName", "Bstack-[Java] Sample file download"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');var capabilities = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Node] Sample file download","userName" : "YOUR_USERNAME","accessKey" : "YOUR_ACCESS_KEY",},"browserName" : "Chrome","browserVersion" : "latest",}async function main() { let driver = new webdriver.Builder() .usingServer('') .withCapabilities(capabilities) .build(); await driver.get('') await driver.findElement(By.id("accept-cookie-notification")).click(); const element = await driver.findElement(By.className('icon-csv')) await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') await element.click() sleep.sleep(2); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.Chrome;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; ChromeOptions capability = new ChromeOptions(); ChromeOptions capabilities = new ChromeOptions(); capabilities.BrowserVersion = "latest"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("projectName", "Bstack-[C_sharp] Sample file download"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "Chrome"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; driver.Navigate().GoToUrl(""); Thread.Sleep(2000); driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by link text and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); Element.Click(); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Python] Sample file download",},"browserName" : "Chrome","browserVersion" : "latest",}options.set_capability('bstack:options', desired_cap)driver = webdriver.Remote( command_executor=', options=options)driver.get("")time.sleep(2)# Accept the cookie popupdriver.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 fileelement.click()time.sleep(2)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescapabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10","projectName" => "Bstack-[Ruby] Sample file download",},"browserName" => "Chrome","browserVersion" => "latest",} driver = Selenium::WebDriver.for( :remote, :url => "", :capabilities => capabilities)driver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)driver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("browser", "Chrome"); caps.setCapability("browser_version", "latest"); caps.setCapability("name", "Bstack-[Java] Sample file download"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');// Input capabilitieslet capabilities = { 'browserName' : 'Chrome', 'browser_version' : 'latest', 'os': 'Windows', 'os_version': '10', 'browserstack.user': 'YOUR_USERNAME', 'browserstack.key': 'YOUR_ACCESS_KEY', 'name': 'Bstack-[Node] Sample file download'}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); await driver.get('') await driver.findElement(By.id("accept-cookie-notification")).click(); const element = await driver.findElement(By.className('icon-csv')) await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') await element.click() sleep.sleep(2); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.Chrome;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; ChromeOptions capability = new ChromeOptions(); capability.AddAdditionalCapability("browser", "Chrome", true); capability.AddAdditionalCapability("browser_version", "latest", true); capability.AddAdditionalCapability("os", "Windows", true); capability.AddAdditionalCapability("os_version", "10", true); capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true); capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true); capability.AddAdditionalCapability("name", "Bstack-[C_sharp] Sample file download", true); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; driver.Navigate().GoToUrl(""); Thread.Sleep(2000); driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by link text and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); Element.Click(); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = { 'browser': 'Chrome', 'browser_version': 'latest', 'os': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)driver.get("")time.sleep(2)# Accept the cookie popupdriver.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 fileelement.click()time.sleep(2)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescaps = Selenium::WebDriver::Remote::Capabilities.newcaps['browser'] = 'Chrome'caps['browser_version'] = 'latest'caps['os'] = 'Windows'caps['os_version'] = '10'caps['name'] = 'Bstack-[Ruby] Sample file download'caps['javascriptEnabled'] = 'true' driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)driver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)driver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { public static final String USERNAME = "YOUR_USERNAME"; public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "IE"); capabilities.setCapability("browserVersion", "11.0"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); browserstackOptions.put("projectName", "Bstack-[Java] Sample file download"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');// Input capabilitiesvar capabilities = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Node] Sample file download","local" : "false","seleniumVersion" : "3.5.2","userName" : "YOUR_USERNAME","accessKey" : "YOUR_ACCESS_KEY",},"browserName" : "IE","browserVersion" : "11.0",}async function main() { let driver = new webdriver.Builder() .usingServer('') .withCapabilities(capabilities) .build(); await driver.get('') await driver.findElement(By.id('accept-cookie-notification')).click() const element = await driver.findElement(By.className('icon-csv')) await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') await element.click() sleep.sleep(2); // Execute this action to click "Save File" button in the browser prompt await driver.executeScript('browserstack_executor: {"action": "saveFile"}') await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.IE;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; InternetExplorerOptions capabilities = new InternetExplorerOptions(); capabilities.BrowserVersion = "11.0"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("projectName", "Bstack-[C#] Sample file download"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "IE"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; driver.Navigate().GoToUrl(""); Thread.Sleep(2000); driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by link text and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); Element.Click(); Thread.Sleep(2000); jse.ExecuteScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Python] Sample file download",},"browserName" : "IE","browserVersion" : "11.0",}options.set_capability('bstack:options', desired_cap)driver = webdriver.Remote( command_executor=', options=options)driver.get("")time.sleep(2)# Accept the cookie popupdriver.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 fileelement.click()time.sleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')time.sleep(2)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescapabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10","projectName" => "Bstack-[Ruby] Sample file download",},"browserName" => "IE","browserVersion" => "11.0",}driver = Selenium::WebDriver.for( :remote, :url => "", :capabilities => capabilities)driver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')sleep(2)driver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { public static final String USERNAME = "YOUR_USERNAME"; public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("browser", "IE"); caps.setCapability("browser_version", "11.0"); caps.setCapability("name", "Bstack-[Java] Sample file download"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; driver.get(""); Thread.sleep(2000); driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');// Input capabilitieslet capabilities = { 'browserName' : 'IE', 'browser_version' : '11.0', 'os': 'Windows', 'os_version': '10', 'browserstack.user': 'YOUR_USERNAME', 'browserstack.key': 'YOUR_ACCESS_KEY', 'name': 'Bstack-[Node] Sample file download'}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); await driver.get('') await driver.findElement(By.id('accept-cookie-notification')).click() const element = await driver.findElement(By.className('icon-csv')) await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') await element.click() sleep.sleep(2); // Execute this action to click "Save File" button in the browser prompt await driver.executeScript('browserstack_executor: {"action": "saveFile"}') await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.IE;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; InternetExplorerOptions capability = new InternetExplorerOptions(); capability.AddAdditionalCapability("browser", "IE",true); capability.AddAdditionalCapability("browser_version", "11.0", true); capability.AddAdditionalCapability("os", "Windows", true); capability.AddAdditionalCapability("os_version", "10", true); capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true); capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true); capability.AddAdditionalCapability("name", "Bstack-[C_sharp] Sample file download", true); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; driver.Navigate().GoToUrl(""); Thread.Sleep(2000); driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by link text and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); Element.Click(); Thread.Sleep(2000); jse.ExecuteScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = { 'browser': 'IE', 'browser_version': '11.0', 'os': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)driver.get("")time.sleep(2)# Accept the cookie popupdriver.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 fileelement.click()time.sleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')time.sleep(2)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescaps = Selenium::WebDriver::Remote::Capabilities.newcaps['browser'] = 'IE'caps['browser_version'] = '11.0'caps['os'] = 'Windows'caps['os_version'] = '10'caps['nativeEvents'] = 'true'caps['name'] = 'Bstack-[Ruby] Sample file download'caps['javascriptEnabled'] = 'true' driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)driver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')sleep(2)driver.quit if driver

Work with the downloaded file

Use the information in the following tabs to learn about different Javascript executors that BrowserStack provides to verify the downloded file:

Protip: Any of the custom Javascript executors will work even if fileName argument is not passed. The results will be for the last downloaded file in the session.

System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"<file name>\"}}"));
await.driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "<file name>"}}')
driver.ExecuteScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "<file name>"}}');
driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "<file name>"}}')
caps['javascriptEnabled'] = 'true' #Additionally, include this capability for JavaScript executors to workdriver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "<file name>"}}')

The fileExists function within the browserstack_executor script returns a boolean value as a response.

Use the above code snippets to verify whether a specific file was downloaded.

Protip: The following snippet verifies whether the last file was downloaded in the test session.
System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\"}"));
await.driver.executeScript('browserstack_executor: {"action": "fileExists"}')
driver.ExecuteScript('browserstack_executor: {"action": "fileExists"}');
driver.execute_script('browserstack_executor: {"action": "fileExists"}')
caps['javascriptEnabled'] = 'true' #Additionally, include this capability for JavaScript executors to workdriver.execute_script('browserstack_executor: {"action": "fileExists"}')
System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"<file name>\"}}"));
await.driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "<file name>"}}')
driver.ExecuteScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "<file name>"}}');
driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "<file name>"}}')
caps['javascriptEnabled'] = 'true' #Additionally, include this capability for JavaScript executors to workdriver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "<file name>"}}')

You can verify the integrity of the downloaded file using the getFileProperties function in your code using the above code snippet. The function returns a JSON response as follows:

{"created_time":1607951826,"md5":"71d277eaaa7b2ba6f63eda04dad1a6b4","changed_time":1607951826,"modified_time":1607951826,"size":3187,"file_name":"Browserstack-List of devices to test.csv"}

The properties’ parameters are defined as follows:

  • created_time: The time when file was downloaded.
  • md5: The md5 checksum value of the downloaded file. You can verify the integrity of the file using this value.
  • changed_time: The time at which the file permission or file content is changed.
  • modified_time: The time at which the file content is changed.
  • size: The size of the downloaded file.
  • file_name: The name of the downloaded file.
System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"<file name>\"}}"));
await.driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "<file name>"}}')
driver.ExecuteScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "<file name>"}}');
driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "<file name>"}}')
caps['javascriptEnabled'] = 'true' #Additionally, include this capability for JavaScript executors to workdriver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "<file name>"}}')

You can transfer the downloaded file from the BrowserStack remote instance to your machine using the getFileContent function that returns the downloaded file as a Base64-encoded string. If you do not know the file name, you can get the content of the last downloaded file in the session by omitting the fileName argument. Use 'browserstack_executor: {"action": "getFileContent"}' and save the response in your local system as shown in the above code sample.

You can use the BrowserStack executor, getFileContent, to download a file that’s up to 30 MB in size.

Sample Code that uses the executors

The following sample code is a cumulative script that downloads a file, and then uses all the supported Javascript executors that BrowserStack provides:

import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.firefox.FirefoxProfile;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class script { public static final String USERNAME = "YOUR_USERNAME"; public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@"; 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"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "Firefox"); capabilities.setCapability("browserVersion", "latest"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup WebElement pop = driver.findElement(By.id("accept-cookie-notification")); pop.click(); // Find element by class name and store in variable "Element"  WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found  jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 and write to a file byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); 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) => { var capabilities = { 'bstack:options' : { "os" : "Windows", "osVersion" : "10", "userName" : "YOUR_USERNAME", "accessKey" : "YOUR_ACCESS_KEY", }, "browserName" : "Firefox", "browserVersion" : "latest", } var driver = new webdriver.Builder(). usingServer('').withCapabilities(capabilities).build(); // Navigate to the link driver.get('').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() { // Check if file exists driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(result) { sleep.sleep(2); console.log(result); // Check file properties driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(file) { console.log(file); // Get file content.The content is Base64 encoded driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(content) { // Decode the content to Base64 and write to a file decoded_data = Buffer.from(content, 'base64'); fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function(err) { 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;namespace downloading_files { class MainClass { 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/force-download"); FirefoxOptions capabilities = new FirefoxOptions(); capabilities.BrowserVersion = "latest"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("buildName", "Selenium C# Firefox Profile"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "Firefox"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); // Encoded profile is added ffOpts.Add("profile", "UEsDBBQAAAAIAFydlE9vNRdlIQQAAOkOAAAHAAAAdXNlci5qc5VXTW/jNhC991cUPrVAzSa73Ut7cmMXKBA0xbrB9kZQ1MhiTJEsh7Tif9+haK+dtb5yEyUOOR/vvRlFBM+dh+qHRSmC8OCsD8rsmLNaySNLL7exaBSisubv7uVKSnABysVP31dCI/z423fxckzhbUsrVtrWaCtK1ggjdvSisjLilxrMlu5Jd/Tbl7Yhk1cua28b4Ci9coH7aHhQDZDNx7u3Bi0UpVcHWoMRhQZuRKAlhwOYgGQQfOy5I4fKhdb8BTm8ppgoxH6Dc1C2qrQy0O/5iziI7C6z+SyGtW3/NA/0aDX0ngyvAQx2m6OjbAPLUczNLn1bn57Xyo86X4N24FfOIRO6FUdc4Z6q4uVAPMK5WT4Fa/VeBRZAQwPBHym3LyAzQobdQRBe1qcbxqNFUUH3nJDZJOf9hE+nQi1FjlbblhdHXkIlog79mHgD/xqEDnVek6f+oCSwSnkMn6Ppv/KCQ4EYCbrR0C1IaeDEngjjxcFEiuhYTaB3xBdu6SSvSmANBttBbqF2xnpYjB+QjGnzXf+uIApklD7zZB60xYm8b54fV+zsyKj7V+c+ORjI0KXynZpQXFRGD12yKmI7l15g3W97yxNjg6qOz9gltscCQUavwpFJdCewzORUZXUJ/lFhuE3klR+FtnKvaddcyjasVYZuYWVs3JXRqCrIGuT+wTaOVK1QOgVk1K4O+jiR5G8AlQAkChvDr4UWZj+AIk2Z9SS24yGdNXpanG9g3YKWSdej1+MelXBIwoKM/CGNyhI6mrSvBa+UBnpi1qudMjy3suTcfN+YKEuVNFxMuHkWPwOhtX5/bnalwhPgbv08bWV1CETXWmF9XKbPjnRjqcHsQuLAh0+fBtvLWBYcEckFTIzkjS2FnijlsOxpu9ull6fcb+aA/I1Sj1786hQpAEkzQ9I1ESIJAYnBf1H5yUuok+lMjHVW9N/zl2G0nurBLYkTLwkcZscT1+d2tHc2wFyEbv+HmeNRGhWmp6Ov5gqdFkcoN/d3279ICbsm/kv/ZgMtoSFBfJ5SXQ0KhqYon+YEFAf4x64V7js+OEecEokgP1vq9GGJwYNoFhOMpF1KBv4tMUd8oVPLFC+EbqL4I7XgFSVIDpBrNL8rDT5Q56PiaBgaOs70zIbL8yRBWA0R302i6JIXo9y5mrNEDHagm6XmbygdDTQF+G23HHDnqnukA9cZ+1tJ4E8W9wOzwU3KZJoQEibXeQAZzjZlaM86bhHWcpN7B/Rpz5ezzQgUMozZZOd4M718ZOLyu3IbwEWF2loRf1M3HxehqzGvO/hqzJOErvH/h5vQRUbk5t/N8Ng048dsljZfipQA4nNrG6gRgq4wugzhnPBFP02kcOl3a5m2Cr08z8qzhIZelU8m1x7v75iiVNrnz48Tk8H0pH57+/9QSwECFAMUAAAACABcnZRPbzUXZSEEAADpDgAABwAAAAAAAAAAAAAApIEAAAAAdXNlci5qc1BLBQYAAAAAAQABADUAAABGBAAAAAA="); caps.SetCapability("moz:firefoxOptions", ffOpts); Console.WriteLine(caps.ToString()); RemoteWebDriver driver = new RemoteWebDriver(new Uri(""), caps); // Navigate to the link driver.Navigate().GoToUrl(""); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; Thread.Sleep(2000); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found driver.ExecuteScript("arguments[0].scrollIntoView();", Element); driver.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(5000); // Check if file exists bool val1 = (bool) driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string) jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesimport timeimport base64profile = 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 = {'bstack:options' : {"os" : "Windows","osVersion" : "10",},"browserName" : "Firefox","browserVersion" : "latest",}driver = webdriver.Remote( command_executor=', desired_capabilities=desired_cap, browser_profile=profile)# Navigate to the linkdriver.get("")# Accept the cookie popuptest=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")# This will scroll the page till the element is found driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Check if file existsfile_exists=driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');print(file_exists)# Check file propertiesfile_properties=driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');print(file_properties)# Get file content. The content is Base64 encodedget_file_content=driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)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"capabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10", "javascriptEnabled" => "true"},"browserName" => "Firefox","browserVersion" => "latest",}driver = Selenium::WebDriver.for(:remote, :url => "", :desired_capabilities => caps)# Navigate to the linkdriver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")# This will scroll the page till the element is found driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# print file properties hashputs(file_properties)# Get file content.The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64 and write to a filedecoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)driver.quit
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.firefox.FirefoxProfile;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class script { public static final String USERNAME = "YOUR_USERNAME"; public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@"; 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"); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("browser", "Firefox"); caps.setCapability("browser_version", "latest"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("name", "Bstack-[Java] Sample file download"); caps.setCapability(FirefoxDriver.PROFILE, profile); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup WebElement pop = driver.findElement(By.id("accept-cookie-notification")); pop.click(); // Find element by class name and store in variable "Element"  WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found  jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 and write to a file byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); 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', 'name': 'Bstack-[Node] Sample file download', 'firefox_profile': encoded } var driver = new webdriver.Builder(). usingServer('').withCapabilities(capabilities).build(); // Navigate to the link driver.get('').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() { // Check if file exists driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(result) { sleep.sleep(2); console.log(result); // Check file properties driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(file) { console.log(file); // Get file content.The content is Base64 encoded driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}').then(function(content) { // Decode the content to Base64 and write to a file decoded_data = Buffer.from(content, 'base64'); fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function(err) { 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;namespace downloading_files { class MainClass { 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/force-download"); DesiredCapabilities caps = new DesiredCapabilities(); caps.SetCapability("os", "windows"); caps.SetCapability("os_version", "10"); caps.SetCapability("name", "Bstack-[C_sharp] Sample file download"); caps.SetCapability("browser", "firefox"); caps.SetCapability("browser_version", "latest"); caps.SetCapability("browserstack.user", "YOUR_USERNAME"); caps.SetCapability("browserstack.key", "YOUR_ACCESS_KEY"); caps.SetCapability("firefox_profile", firefoxProfile.ToBase64String()); Dictionary < string, object > ffOpts = new Dictionary < string, object > (); // Encoded profile is added ffOpts.Add("profile", "UEsDBBQAAAAIAFydlE9vNRdlIQQAAOkOAAAHAAAAdXNlci5qc5VXTW/jNhC991cUPrVAzSa73Ut7cmMXKBA0xbrB9kZQ1MhiTJEsh7Tif9+haK+dtb5yEyUOOR/vvRlFBM+dh+qHRSmC8OCsD8rsmLNaySNLL7exaBSisubv7uVKSnABysVP31dCI/z423fxckzhbUsrVtrWaCtK1ggjdvSisjLilxrMlu5Jd/Tbl7Yhk1cua28b4Ci9coH7aHhQDZDNx7u3Bi0UpVcHWoMRhQZuRKAlhwOYgGQQfOy5I4fKhdb8BTm8ppgoxH6Dc1C2qrQy0O/5iziI7C6z+SyGtW3/NA/0aDX0ngyvAQx2m6OjbAPLUczNLn1bn57Xyo86X4N24FfOIRO6FUdc4Z6q4uVAPMK5WT4Fa/VeBRZAQwPBHym3LyAzQobdQRBe1qcbxqNFUUH3nJDZJOf9hE+nQi1FjlbblhdHXkIlog79mHgD/xqEDnVek6f+oCSwSnkMn6Ppv/KCQ4EYCbrR0C1IaeDEngjjxcFEiuhYTaB3xBdu6SSvSmANBttBbqF2xnpYjB+QjGnzXf+uIApklD7zZB60xYm8b54fV+zsyKj7V+c+ORjI0KXynZpQXFRGD12yKmI7l15g3W97yxNjg6qOz9gltscCQUavwpFJdCewzORUZXUJ/lFhuE3klR+FtnKvaddcyjasVYZuYWVs3JXRqCrIGuT+wTaOVK1QOgVk1K4O+jiR5G8AlQAkChvDr4UWZj+AIk2Z9SS24yGdNXpanG9g3YKWSdej1+MelXBIwoKM/CGNyhI6mrSvBa+UBnpi1qudMjy3suTcfN+YKEuVNFxMuHkWPwOhtX5/bnalwhPgbv08bWV1CETXWmF9XKbPjnRjqcHsQuLAh0+fBtvLWBYcEckFTIzkjS2FnijlsOxpu9ull6fcb+aA/I1Sj1786hQpAEkzQ9I1ESIJAYnBf1H5yUuok+lMjHVW9N/zl2G0nurBLYkTLwkcZscT1+d2tHc2wFyEbv+HmeNRGhWmp6Ov5gqdFkcoN/d3279ICbsm/kv/ZgMtoSFBfJ5SXQ0KhqYon+YEFAf4x64V7js+OEecEokgP1vq9GGJwYNoFhOMpF1KBv4tMUd8oVPLFC+EbqL4I7XgFSVIDpBrNL8rDT5Q56PiaBgaOs70zIbL8yRBWA0R302i6JIXo9y5mrNEDHagm6XmbygdDTQF+G23HHDnqnukA9cZ+1tJ4E8W9wOzwU3KZJoQEibXeQAZzjZlaM86bhHWcpN7B/Rpz5ezzQgUMozZZOd4M718ZOLyu3IbwEWF2loRf1M3HxehqzGvO/hqzJOErvH/h5vQRUbk5t/N8Ng048dsljZfipQA4nNrG6gRgq4wugzhnPBFP02kcOl3a5m2Cr08z8qzhIZelU8m1x7v75iiVNrnz48Tk8H0pH57+/9QSwECFAMUAAAACABcnZRPbzUXZSEEAADpDgAABwAAAAAAAAAAAAAApIEAAAAAdXNlci5qc1BLBQYAAAAAAQABADUAAABGBAAAAAA="); caps.SetCapability("moz:firefoxOptions", ffOpts); Console.WriteLine(caps.ToString()); RemoteWebDriver driver = new RemoteWebDriver(new Uri(""), caps); // Navigate to the link driver.Navigate().GoToUrl(""); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; Thread.Sleep(2000); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found driver.ExecuteScript("arguments[0].scrollIntoView();", Element); driver.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(5000); // Check if file exists bool val1 = (bool) driver.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string) jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesimport timeimport base64profile = 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': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor=', desired_capabilities=desired_cap, browser_profile=profile)# Navigate to the linkdriver.get("")# Accept the cookie popuptest=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")# This will scroll the page till the element is found driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Check if file existsfile_exists=driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');print(file_exists)# Check file propertiesfile_properties=driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');print(file_properties)# Get file content. The content is Base64 encodedget_file_content=driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}');time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)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"caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)caps['browser'] = 'Firefox'caps['browser_version'] = 'latest'caps['os'] = 'Windows'caps['os_version'] = '10'caps['name'] = 'Bstack-[Ruby] Sample file download'caps['javascriptEnabled'] = 'true' driver = Selenium::WebDriver.for(:remote, :url => "", :desired_capabilities => caps)# Navigate to the linkdriver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")# This will scroll the page till the element is found driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# print file properties hashputs(file_properties)# Get file content.The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64 and write to a filedecoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)driver.quit

Test download functionality in the different browsers including Chrome, Edge, and Safari.

import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "Chrome"); capabilities.setCapability("browserVersion", "latest"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); browserstackOptions.put("projectName", "Bstack-[Java] Sample file download"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");// Input capabilitiesvar capabilities = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Node] Sample file download","userName" : "YOUR_USERNAME","accessKey" : "YOUR_ACCESS_KEY",},"browserName" : "Chrome","browserVersion" : "latest",}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); // Navigate to the link await driver.get('') // Accept the cookie popup await driver.findElement(By.id('accept-cookie-notification')).click() // Find element by class name const element = await driver.findElement(By.className('icon-csv')) // This will scroll the page till the element is found await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') // Click on the element to download the file await element.click() // Returns bool if file exists let val1 = await driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val1) // Returns hash of file properties let val2 =await driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val2) // Download file let data = await driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') let decoded_data = Buffer.from(data, 'base64'); await fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function (err) { if (err) throw err; console.log('File created') }); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.Chrome;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; ChromeOptions capability = new ChromeOptions(); ChromeOptions capabilities = new ChromeOptions(); capabilities.BrowserVersion = "latest"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("projectName", "Bstack-[C_sharp] Sample file download"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "Chrome"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; // Navigate to the link driver.Navigate().GoToUrl(""); Thread.Sleep(2000); // Accept the cookie popup driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(2000); // Check if file exists bool val1 = (bool) jse.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string) jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Python] Sample file download",},"browserName" : "Chrome","browserVersion" : "latest",}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)# Navigate to the linkdriver.get("")time.sleep(2)# Accept the cookie popupdriver.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")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')print file_exists# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashprint file_properties# Download fileget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescapabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10","projectName" => "Bstack-[Ruby] Sample file download",},"browserName" => "Chrome","browserVersion" => "latest",}driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)# Navigate to the linkdriver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# print file properties hashputs(file_properties)# Get file content. The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64decoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)f.closedriver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("browser", "Chrome"); caps.setCapability("browser_version", "latest"); caps.setCapability("name", "Bstack-[Java] Sample file download"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");// Input capabilitieslet capabilities = { 'browserName' : 'Chrome', 'browser_version' : 'latest', 'os': 'Windows', 'os_version': '10', 'browserstack.user': 'YOUR_USERNAME', 'browserstack.key': 'YOUR_ACCESS_KEY', 'name': 'Bstack-[Node] Sample file download'}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); // Navigate to the link await driver.get('') // Accept the cookie popup await driver.findElement(By.id('accept-cookie-notification')).click() // Find element by class name const element = await driver.findElement(By.className('icon-csv')) // This will scroll the page till the element is found await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') // Click on the element to download the file await element.click() // Returns bool if file exists let val1 = await driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val1) // Returns hash of file properties let val2 =await driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val2) // Download file let data = await driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') let decoded_data = Buffer.from(data, 'base64'); await fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function (err) { if (err) throw err; console.log('File created') }); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.Chrome;using System.IO;using System.Threading;namespace SeleniumTest { class FileDownload { static void Main(string[] args) { IWebDriver driver; ChromeOptions capability = new ChromeOptions(); capability.AddAdditionalCapability("browser", "Chrome", true); capability.AddAdditionalCapability("browser_version", "latest", true); capability.AddAdditionalCapability("os", "Windows", true); capability.AddAdditionalCapability("os_version", "10", true); capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true); capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true); capability.AddAdditionalCapability("name", "Bstack-[C_sharp] Sample file download", true); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor) driver; // Navigate to the link driver.Navigate().GoToUrl(""); Thread.Sleep(2000); // Accept the cookie popup driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(2000); // Check if file exists bool val1 = (bool) jse.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string) jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = { 'browser': 'Chrome', 'browser_version': 'latest', 'os': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)# Navigate to the linkdriver.get("")time.sleep(2)# Accept the cookie popupdriver.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")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')print file_exists# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashprint file_properties# Download fileget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescaps = Selenium::WebDriver::Remote::Capabilities.newcaps['browser'] = 'Chrome'caps['browser_version'] = 'latest'caps['os'] = 'Windows'caps['os_version'] = '10'caps['name'] = 'Bstack-[Ruby] Sample file download'caps['javascriptEnabled'] = 'true' driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)# Navigate to the linkdriver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# print file properties hashputs(file_properties)# Get file content. The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64decoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)f.closedriver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserName", "IE"); capabilities.setCapability("browserVersion", "11.0"); HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); browserstackOptions.put("os", "Windows"); browserstackOptions.put("osVersion", "10"); browserstackOptions.put("projectName", "Bstack-[Java] Sample file download"); capabilities.setCapability("bstack:options", browserstackOptions); WebDriver driver = new RemoteWebDriver(new URL(URL), capabilities); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Execute this action to click "Save File" button in the browser prompt jse.executeScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');// Input capabilitiesvar capabilities = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Node] Sample file download","local" : "false","seleniumVersion" : "3.5.2","userName" : "YOUR_USERNAME","accessKey" : "YOUR_ACCESS_KEY",},"browserName" : "IE","browserVersion" : "11.0",}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); // Navigate to the link await driver.get('') // Accept the cookie popup await driver.findElement(By.id('accept-cookie-notification')).click() // Find element by class name and store in variable "element"  const element = await driver.findElement(By.className('icon-csv')) // This will scroll the page till the element is found  await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') // Click on the element to download the file await element.click() sleep.sleep(2); await driver.executeScript('browserstack_executor: {"action": "saveFile"}') // Check if file exists let val1 = await driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val1) // Get file properties let val2 = await driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val2) // Download the file locally let data = await driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') let decoded_data = Buffer.from(data, 'base64'); await fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function (err) { if (err) throw err; console.log('File created') }); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.IE;using System.IO;using System.Threading;namespace SeleniumTest{ class FileDownload { static void Main(string[] args) { IWebDriver driver; InternetExplorerOptions capabilities = new InternetExplorerOptions(); capabilities.BrowserVersion = "11.0"; Dictionary<string, object> browserstackOptions = new Dictionary<string, object>(); browserstackOptions.Add("os", "Windows"); browserstackOptions.Add("osVersion", "10"); browserstackOptions.Add("projectName", "Bstack-[C#] Sample file download"); browserstackOptions.Add("userName", "YOUR_USERNAME"); browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY"); browserstackOptions.Add("browserName", "IE"); capabilities.AddAdditionalOption("bstack:options", browserstackOptions); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor)driver; // Navigate to the link driver.Navigate().GoToUrl(""); Thread.Sleep(2000); // Accept the cookie popup driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(2000); jse.ExecuteScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.Sleep(2000); // Check if file exists bool val1 = (bool)jse.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string)jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = {'bstack:options' : {"os" : "Windows","osVersion" : "10","projectName" : "Bstack-[Python] Sample file download",},"browserName" : "IE","browserVersion" : "11.0",}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)# Navigate to the linkdriver.get("")time.sleep(2)# Accept the cookie popupdriver.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")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')time.sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')print file_exists# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashprint file_properties# Download fileget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescapabilities = {'bstack:options' => {"os" => "Windows","osVersion" => "10","projectName" => "Bstack-[Ruby] Sample file download",},"browserName" => "IE","browserVersion" => "11.0",}driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)driver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashputs(file_properties)# Get file content.The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64decoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)f.closedriver.quit if driver
import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.Base64;import java.net.URL;public class FileDownload { 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 + "@"; public static void main(String[] args) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("browser", "IE"); caps.setCapability("browser_version", "11.0"); caps.setCapability("name", "Bstack-[Java] Sample file download"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); JavascriptExecutor jse = (JavascriptExecutor) driver; // Navigate to the link driver.get(""); Thread.sleep(2000); // Accept the cookie popup driver.findElement(By.id("accept-cookie-notification")).click(); // Find element by class name and store in variable "Element" WebElement Element = driver.findElement(By.className("icon-csv")); // This will scroll the page till the element is found jse.executeScript("arguments[0].scrollIntoView();", Element); jse.executeScript("window.scrollBy(0,-100)"); Thread.sleep(1000); // Click on the element to download the file Element.click(); Thread.sleep(2000); // Execute this action to click "Save File" button in the browser prompt jse.executeScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.sleep(2000); // Check if file exists System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file properties System.out.println(jse.executeScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Get file content. The content is Base64 encoded String base64EncodedFile = (String) jse.executeScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); // Decode the content to Base64 byte[] data = Base64.getDecoder().decode(base64EncodedFile); OutputStream stream = new FileOutputStream("BrowserStack%20-%20List%20of%20devices%20to%20test%20on.csv"); stream.write(data); stream.close(); driver.quit(); }}
const {Builder, By, Key, until} = require('selenium-webdriver');const fs = require("fs");var sleep = require('sleep');// Input capabilitieslet capabilities = { 'browserName' : 'IE', 'browser_version' : '11.0', 'os': 'Windows', 'os_version': '10', 'browserstack.user': 'YOUR_USERNAME', 'browserstack.key': 'YOUR_ACCESS_KEY', 'name': 'Bstack-[Node] Sample file download'}async function main() { let driver = await new Builder() .usingServer('') .withCapabilities(capabilities) .build(); // Navigate to the link await driver.get('') // Accept the cookie popup await driver.findElement(By.id('accept-cookie-notification')).click() // Find element by class name and store in variable "element"  const element = await driver.findElement(By.className('icon-csv')) // This will scroll the page till the element is found  await driver.executeScript('arguments[0].scrollIntoView();', element) await driver.executeScript('window.scrollBy(0,-200)') // Click on the element to download the file await element.click() sleep.sleep(2); await driver.executeScript('browserstack_executor: {"action": "saveFile"}') // Check if file exists let val1 = await driver.executeScript('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val1) // Get file properties let val2 = await driver.executeScript('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') console.log(val2) // Download the file locally let data = await driver.executeScript('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}') let decoded_data = Buffer.from(data, 'base64'); await fs.writeFile('BrowserStack - List of devices to test on.csv', decoded_data, function (err) { if (err) throw err; console.log('File created') }); await driver.quit()}main()
using System;using OpenQA.Selenium;using OpenQA.Selenium.Remote;using OpenQA.Selenium.IE;using System.IO;using System.Threading;namespace SeleniumTest{ class FileDownload { static void Main(string[] args) { IWebDriver driver; InternetExplorerOptions capability = new InternetExplorerOptions(); capability.AddAdditionalCapability("browser", "IE", true); capability.AddAdditionalCapability("browser_version", "11.0", true); capability.AddAdditionalCapability("os", "Windows", true); capability.AddAdditionalCapability("os_version", "10", true); capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true); capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true); capability.AddAdditionalCapability("name", "Bstack-[C_sharp] Sample file download", true); driver = new RemoteWebDriver( new Uri(""), capability ); IJavaScriptExecutor jse = (IJavaScriptExecutor)driver; // Navigate to the link driver.Navigate().GoToUrl(""); Thread.Sleep(2000); // Accept the cookie popup driver.FindElement(By.Id("accept-cookie-notification")).Click(); // Find element by class name and store in variable "Element"  IWebElement Element = driver.FindElement(By.ClassName("icon-csv")); // This will scroll the page till the element is found  jse.ExecuteScript("arguments[0].scrollIntoView();", Element); jse.ExecuteScript("window.scrollBy(0,-100)"); Thread.Sleep(2000); // Click on the element to download the file Element.Click(); Thread.Sleep(2000); jse.ExecuteScript("browserstack_executor: {\"action\": \"saveFile\"}"); Thread.Sleep(2000); // Check if file exists bool val1 = (bool)jse.ExecuteScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); Console.WriteLine(val1); // Get file properties Console.WriteLine(jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileProperties\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}")); // Download the file locally jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); string base64encode = (string)jse.ExecuteScript("browserstack_executor: {\"action\": \"getFileContent\", \"arguments\": {\"fileName\": \"BrowserStack - List of devices to test on.csv\"}}"); byte[] b = Convert.FromBase64String(base64encode); File.WriteAllBytes(@"BrowserStack - List of devices to test on.csv", b); Thread.Sleep(2000); driver.Quit(); } }}
from selenium import webdriverimport timeimport base64desired_cap = { 'browser': 'IE', 'browser_version': '11.0', 'os': 'Windows', 'os_version': '10', 'name': 'Bstack-[Python] Sample file download'}driver = webdriver.Remote( command_executor = ', desired_capabilities = desired_cap)# Navigate to the linkdriver.get("")time.sleep(2)# Accept the cookie popupdriver.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")# This will scroll the page till the element is founddriver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")time.sleep(2)# Click on the element to download the fileelement.click()time.sleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')time.sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')print file_exists# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashprint file_properties# Download fileget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')time.sleep(2)# Decode the content to Base64 and write to a filedata = base64.b64decode(get_file_content)f = open("BrowserStack - List of devices to test on.csv", "wb")f.write(data)driver.quit()
require 'rubygems'require 'selenium-webdriver'# Input capabilitiescaps = Selenium::WebDriver::Remote::Capabilities.newcaps['browser'] = 'IE'caps['browser_version'] = '11.0'caps['os'] = 'Windows'caps['os_version'] = '10'caps['nativeEvents'] = 'true'caps['name'] = 'Bstack-[Ruby] Sample file download'driver = Selenium::WebDriver.for(:remote,:url => "",:desired_capabilities => caps)# Navigate to the linkdriver.navigate.to ""sleep(2)# Accept the cookie popupdriver.find_element(:id, "accept-cookie-notification").click# Find element by class name and store in variable "element"element = driver.find_element(:class_name, "icon-csv")driver.execute_script("arguments[0].scrollIntoView();", element)driver.execute_script("window.scrollBy(0,-100)")sleep(2)# Click on the element to download the fileelement.clicksleep(2)# Execute this action to click "Save File" button in the browser promptdriver.execute_script('browserstack_executor: {"action": "saveFile"}')sleep(2)# Check if file existsfile_exists = driver.execute_script('browserstack_executor: {"action": "fileExists", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Return bool if file exists or notputs(file_exists)# Get file propertiesfile_properties = driver.execute_script('browserstack_executor: {"action": "getFileProperties", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Print file properties hashputs(file_properties)# Get file content.The content is Base64 encodedget_file_content = driver.execute_script('browserstack_executor: {"action": "getFileContent", "arguments": {"fileName": "BrowserStack - List of devices to test on.csv"}}')# Decode the content to Base64decoded_content = Base64.decode64(get_file_content);f = File.open("BrowserStack - List of devices to test on.csv", "wb")f.write(decoded_content)f.closedriver.quit if driver

Check this page for a list of various JavaScript Executors that BrowserStack offers.

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

Is this page helping you?

Yes No

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!