vgc
vgc

Reputation: 21

How to upload different filename and with latest Date/Time stamp using Selenium WebDriver in Java

My code:

WebElement choosefile = driver.findElement(By.xpath("//*[@id='ctl00_MainContent_flUpload']"));
choosefile.sendKeys("/Users/ExcelFiles/test.xlsx");

My question: Here I am only uploading test.xlsx file, If I want to upload different file name with .xlsx extension, which has a latest Date and Time stamp. Please let me know how to to do that.

Upvotes: 1

Views: 816

Answers (1)

TitusLucretius
TitusLucretius

Reputation: 181

Looking at this answer shows that you can do this by:

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM_dd_yyyy_h:mm:ss a");
String formattedDate = sdf.format(date);

WebElement choosefile = driver.findElement(By.xpath("//*[@id='ctl00_MainContent_flUpload']"));
choosefile.sendKeys("/Users/ExcelFiles/test" + formattedDate + ".xlsx");

Upvotes: 1

Related Questions