Wednesday 1 June 2022

How To Set Download Path in Chrome using Selenium Java

                     In this post, we will see How To Set Download Path in Chrome using Selenium Java 


Program Code:

import java.util.HashMap;

import java.util.Map;



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;


public class SetDownloadDefaultDirectory {


public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

ChromeOptions options=new ChromeOptions();

Map<String, Object> prefs = new HashMap<String, Object>();


prefs.put("download.default_directory", "C:\\Users\\parag\\Downloads\\sample");


options.setExperimentalOption("prefs", prefs);

WebDriver driver=new ChromeDriver(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=6WycLnfGBYk

No comments:

Post a Comment