package com.autoit;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
public class FileUpload {
public static void main(String[] args) throws InterruptedException, IOException {
try{
WebDriver driver;
String downloadPath=System.getProperty("user.dir");//using this steps we will get System path means project path F:\MyWorkSpace\Selenium_Batch_2018
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
//By using below line of code to copy the downlaod file in project locations
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory",downloadPath);
ChromeOptions options=new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
driver=new ChromeDriver(options);
driver.get("https://www.ilovepdf.com/word_to_pdf");
driver.findElement(By.xpath("//span[contains(text(),'Select WORD files')]")).click();
Thread.sleep(3000);
Runtime.getRuntime().exec("D:\\fileupload.exe");
Thread.sleep(3000);
// WebElement ele =driver.findElement(By.id("processTask")).click();
WebElement ele=driver.findElement(By.cssSelector("#processTask"));
Actions act=new Actions(driver);
act.moveToElement(ele).click().build().perform();
Thread.sleep(3000);
//driver.findElement(By.id("pickfiles")).click();
File f=new File(downloadPath+"/Resume.pdf");
if(f.exists()){
System.out.println("File is downloaded");
if(f.delete()){
System.out.println("File is delated");
}
}
else{
System.out.println("File is not downloaded");
}
System.out.println("***Test case is passed***");
}
catch(Exception e){
System.out.println(e.getMessage());
}
//driver.close();
}
}
=========================================================================
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
public class FileUpload {
public static void main(String[] args) throws InterruptedException, IOException {
try{
WebDriver driver;
String downloadPath=System.getProperty("user.dir");//using this steps we will get System path means project path F:\MyWorkSpace\Selenium_Batch_2018
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
//By using below line of code to copy the downlaod file in project locations
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory",downloadPath);
ChromeOptions options=new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
driver=new ChromeDriver(options);
driver.get("https://www.ilovepdf.com/word_to_pdf");
driver.findElement(By.xpath("//span[contains(text(),'Select WORD files')]")).click();
Thread.sleep(3000);
Runtime.getRuntime().exec("D:\\fileupload.exe");
Thread.sleep(3000);
// WebElement ele =driver.findElement(By.id("processTask")).click();
WebElement ele=driver.findElement(By.cssSelector("#processTask"));
Actions act=new Actions(driver);
act.moveToElement(ele).click().build().perform();
Thread.sleep(3000);
//driver.findElement(By.id("pickfiles")).click();
File f=new File(downloadPath+"/Resume.pdf");
if(f.exists()){
System.out.println("File is downloaded");
if(f.delete()){
System.out.println("File is delated");
}
}
else{
System.out.println("File is not downloaded");
}
System.out.println("***Test case is passed***");
}
catch(Exception e){
System.out.println(e.getMessage());
}
//driver.close();
}
}
=========================================================================
No comments:
Post a Comment