I'm trying to test the date-picker to this site. and selected a date , which resulted in populating a text field with the selected date.
Now I wanted to validate, if the date selected is as expected. I was able to do up to selecting the date and populating the text field.
But when trying to validate the value, I'm getting back spaces from text field.
How can I capture the value populated by date-picker and assert the same ?
I have done to this below mentioned code, but it didn't help me.
driver.get(" https://www.jqueryui.com");
driver.findElement(By.linkText("Datepicker")).click();
WebElement element1 = driver.findElement(By.className("demo-frame"));
driver.switchTo().frame(element1);
driver.findElement(By.xpath(".//*[@id='datepicker']")).click();
driver.findElement(By.xpath("//span[contains(text(),'Next')]")).click();
List<WebElement> element = driver.findElements(By.xpath(".//*[@id='ui-datepicker-div']/table/tbody/tr/td"));
int count = element.size();
for (int i = 0; i < count; i++)
{
String data = element.get(i).getText();
if("2".equals(data))
{
element.get(i).click();
break;
}
}
driver.findElement(By.xpath(".//*[@id='datepicker']")).click();
WebElement element2 = driver.findElement(By.xpath(".//*[@id='datepicker']"));
String value = element2.getText();
Assert.assertEquals("04/02/2017",value);
My expectation is value will hold 04/02/2017
, as 2 was selected. Apparently DOM is not updated. So, what should I be doing here to capture and assert the value selected ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…