Enter / Select date from the calender
Date Set using Java Script.. In calender.
String FutureDate = "28/02/2014";
String javaStringToSetDate = "var x=document.getElementsByName('flight_depart_date”);
x[0].value=" + "'" + FutureDate + "';";
js.executeScript(javaStringToSetDate);
Date selection using JavaScript in a calender (50 Days + from current Date).
now = Calendar.getInstance();
now.add(Calendar.DATE, +50);
String FromDate =(now.get(Calendar.MONTH) + 1) + "/" + now.get(Calendar.DATE) + "/" +
now.get(Calendar.YEAR);
You can use this using JavaScript Executor code below u can send it to the Element.
((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]", driver.findElement(By.id(OR.getProperty("txtSSTODate_ID"))), ToDate);
Another Option to select date :
public void DateSelection()
{
var selectDate = (DateTime.Now.AddDays(50)).ToString("dd'/'MM'/'yyyy");
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("window.document.getElementById('textboxDepDate').setAttribute('value', '" + selectDate + "')");
}
Select items from Drop Down List
var List = driver.FindElement(By.Name("DropdownElement"));
var listElement = new SelectElement(List); //create select element object
listElement.SelectByValue("Mumbai"); //select by value
good one
ReplyDelete