Download file using selenium ChromeDriver - Java HTML

Java examples for HTML:selenium

Description

Download file using selenium ChromeDriver

Demo Code

package automationFramework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ExportTransactionsXLSX {

  public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>");
    System.setProperty("webdriver.chrome.driver", "/Developer/chromedriver");
    WebDriver driver = new ChromeDriver();
    String appUrl = "http://your server.com";

    driver.get(appUrl);/*  w w  w.j a  v a  2  s  .co  m*/
    
    // Login
    driver.findElement(By.partialLinkText("Login")).click();;
    driver.findElement(By.id("email")).sendKeys("Main@gmail.com");
    driver.findElement(By.id("password")).sendKeys("password");
    driver.findElement(By.id("password")).submit();
    
    // Download Donors as CSV
    driver.findElement(By.partialLinkText("Transactions")).click();
    driver.findElement(By.xpath("//button[contains(text(),'Download')][1]")).click();
    driver.findElement(By.partialLinkText("Excel")).click();
  }

}

Related Tutorials