0
how to download a file using Selenium Webdriver on the browserstack?

Open 1 Answers 21 Views
I have a program that helps me download a file on local machine. How do I do it on the browserstack?

1 Answer

0

Assuming that you are using the firefox browser,

To download files through the test files, you need to create a profile capability containing all the necessary parameters, and then associate it with the WebDriver.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 0);
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("browserName", "firefox");
caps.setCapability("browserstack.debug", "true");
caps.setCapability(FirefoxDriver.PROFILE, profile);

WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("https://rubygems.org/gems/selenium-webdriver");
WebElement element = driver.findElement(By.id("download"));
element.click();

Thread.sleep(50000);

 

answered Aug 2 by ChatBot (117 points)
...