Someone asked me: "How to identify a datepicker on the webpage, which will display after clicking the datepicker icon?"
Here is a simple sample, you can customize your own function for reading your web page source and make a api for picking any dates freely :-)
//Find all the Calendar on the Web Page
List<WebElement> Datepickers = driver.findElements(By.className("CalendarIcon"));
//Trigger the calendar of StartDate
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Datepickers.get(0).click();
WebElement table = driver.findElement(By.className("ui-datepicker-calendar"));
List<WebElement> tds = table.findElements(By.tagName("td"));
for (WebElement td: tds){
//Select 20th Date of current month
if (td.getText().equals("20")){
td.findElement(By.linkText("20")).click();
break;
}
}
//Trigger the calendar of EndDate
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Datepickers.get(1).click();
WebElement table2 = driver.findElement(By.className("ui-datepicker-calendar"));
List<WebElement> tds2 = table2.findElements(By.tagName("td"));
for (WebElement td2: tds2){
//Select 22th Date of current month
if (td2.getText().equals("22")){
td2.findElement(By.linkText("22")).click();
break;
}
}
Monday, September 20, 2010
Subscribe to:
Post Comments (Atom)
Super let me try
ReplyDelete//Find all the Calendar on the Web Page
ReplyDeleteList Datepickers = driver.findElements(By.className("CalendarIcon"));
what does WebElement here actualy mean ?
The WebElement means the element on web page have "CalendarIcon" in its class name
DeleteHi Cheng,
DeleteI am using the mentioned code but its not working for me,will u plz help...........
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
//driver.get("http://www.espncricinfo.com/");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://staging.hemscottir.com/ir/template/ir.jsp?page=share-price-calculatorAjax");
//driver.findElement(By.xpath("//*[@id='inp_date']")).click();
List Datepickers = driver.findElements(By.xpath("//*[@id='inp_date']"));
Datepickers.get(0).click();
//Find all the Calendar on the Web Page
// List Datepickers = driver.findElements(By.className("CalendarIcon"));
//Trigger the calendar of StartDate
/*WebElement table = driver.findElement(By.className("datepickerContainer"));
List tds = table.findElements(By.tagName("td"));
for (WebElement td: tds){
//Select 20th Date of current month
if (td.getText().equals("20")){
td.findElement(By.linkText("20")).click();
break;
}
}
//Trigger the calendar of EndDate
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Datepickers.get(1).click();
WebElement table2 = driver.findElement(By.className("datepickerContainer"));
List tds2 = table2.findElements(By.tagName("td"));
for (WebElement td2: tds2){
//Select 22th Date of current month
if (td2.getText().equals("22")){
td2.findElement(By.linkText("22")).click();
break;
}
} */
}
}
Hi i am trying to using link text but value are not working and on my earlier calendar link text was working now what should i do.
ReplyDelete