I am trying to select date from the Datepicker.Following is the code
WebDriver d=new FirefoxDriver();
Actions a=new Actions(d);
String date="14";
d.get("http://www.eyecon.ro/bootstrap-datepicker/");
d.findElement(By.cssSelector("div#dp3>span")).click();
List<WebElement> trs=d.findElements(By.cssSelector("div.datepicker-days>table>tbody>tr"));
for(WebElement tr:trs) {
List<WebElement> tds=tr.findElements(By.tagName("td"));
for(WebElement td:tds) {
if(date.equals(td.getText())) {
a.moveToElement(td).click().build().perform();
}
}
}
With the above code i got stale element reference exception at this line of code
"if(date.equals(td.getText())) {"
so i have changed the code to this
for(WebElement td:tds) {
while(i<4) {
try {
if(date.equals(td.getText())) {
a.moveToElement(td).click().build().perform();
}
break;
}catch(Exception ex) {
}
System.out.println(i);
i++;
}
}
Now i am able to select the date.But the script is still throwing the stale element reference exception.The script is showing error at this line now
List<WebElement> tds=tr.findElements(By.tagName("td"));
I am working on this for the past 3 days.Any suggestions on how to solve this. Thanks in advance