I have a date field that sometimes will get filled out by Webdriver element.sendKeys() and other times the field will just get skipped. (using Chromedriver 2.9).
Element Locator Info:
<input id="dateOfBirth" type="date" class=" form-control " placeholder="">
The code for Entering text and re-trying if fails:
//Web element already verified present and visible before being passed into the method
public static void enterText(WebElement weElement, String textToEnter) {
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: EnteringText: " +textToEnter);
//weElement.click();
weElement.sendKeys(textToEnter);
String textEntered = weElement.getAttribute("value");
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: TextDisplayed is: "+ textEntered);
//continued
int iAttempts = 0;
while (iAttempts < 1) {
if(!textEntered.isEmpty())
break;
else{
System.out.println(" *Thread:" +Thread.currentThread().getId() +" ERROR: re-Attempting to enter text: "+ textToEnter);
//weElement.click();
weElement.sendKeys(textToEnter);
textEntered= weElement.getAttribute("value");
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: Element text after re-attempt: "+ textEntered);
iAttempts++;
}
}
}
The console output:
*Thread:10 Trying: com.xxx.pageobjects.IdentityPage.typeDOB
*Thread:10 INFO: Locator is: [data-model-attribute='dateOfBirth'] input
*Thread:10 INFO: EnteringText: 01/01/1981
*Thread:10 INFO: TextDisplayed is:
*Thread:10 ERROR: re-Attempting to enter text: 01/01/1981
*Thread:10 INFO: Element text after re-attempt:
Does anyone have any ideas as to why this happens only with date fields? And any ideas for a better workaround in case it fails? Thanks!
Note: My app only works on Chrome so I am unable to confirm if the issue happens in other browsers