package com.examples;
import java.io.File;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class File_Download_02 {
@SuppressWarnings("boxing")
public static void main(String[] args) {
// System.setProperty("webdriver.chromedriver.driver", "chromedriver");
String downloadFilepath = "/home/nimesh/Desktop";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("download.directory_upgrade", true);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File("chromedriver"))
.usingAnyFreePort()
.build();
ChromeOptions options1 = new ChromeOptions();
options1.merge(capabilities);
options1.setExperimentalOption("prefs", chromePrefs);
// ChromeDriver driver = new ChromeDriver(service, options);
WebDriver wd = new ChromeDriver(options1);
int i = 0;
if (i == 0) {
wd.get("http://www.sample-videos.com/download-sample-xls.php");
wd.findElement(By.xpath("html/body/div[4]/div[1]/div[2]/div[2]/table/tbody/tr[1]/td[4]/a")).click();
// wd.findElement(By.xpath("html/body/form/input[2]")).sendKeys("Test");
// wd.findElement(By.xpath("html/body/form/input[3]")).click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(wd.getTitle());
}
}
}
import java.io.File;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class File_Download_02 {
@SuppressWarnings("boxing")
public static void main(String[] args) {
// System.setProperty("webdriver.chromedriver.driver", "chromedriver");
String downloadFilepath = "/home/nimesh/Desktop";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("download.directory_upgrade", true);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File("chromedriver"))
.usingAnyFreePort()
.build();
ChromeOptions options1 = new ChromeOptions();
options1.merge(capabilities);
options1.setExperimentalOption("prefs", chromePrefs);
// ChromeDriver driver = new ChromeDriver(service, options);
WebDriver wd = new ChromeDriver(options1);
int i = 0;
if (i == 0) {
wd.get("http://www.sample-videos.com/download-sample-xls.php");
wd.findElement(By.xpath("html/body/div[4]/div[1]/div[2]/div[2]/table/tbody/tr[1]/td[4]/a")).click();
// wd.findElement(By.xpath("html/body/form/input[2]")).sendKeys("Test");
// wd.findElement(By.xpath("html/body/form/input[3]")).click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(wd.getTitle());
}
}
}
No comments:
Post a Comment