In this video, we will see How To Set Download Path in Firefox using Selenium Java
Program Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
public class SetDownloadPathFirefox {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\selenium\\geckodriver-v0.31.0-win64\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
//1. Instructing firefox to use custom download location
profile.setPreference("browser.download.folderList", 2);
//2. Setting custom download directory
profile.setPreference("browser.download.dir", "C:\\Users\\parag\\Downloads\\sample");
//3. Skipping Save As dialog box
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword;application/ms-doc;application/doc;application/pdf;text/plain;application/text;text/xml;application/xml");
options.setProfile(profile);
WebDriver driver=new FirefoxDriver(options);
driver.get("https://www.seleniumhq.org/download/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//a[normalize-space()='4.2.1']")).click();
}
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=SKLxQBNRHVs
No comments:
Post a Comment