I am trying to use the send keys function from selenium to send date of birth text into an input field. The input field has the forward slashes pre-formatted whenever you click on it.
I have tried using the Javascript executer to set the value to the format "07/24/1987" and it does send the value. After I click out of the input box, the values disappear.
This is the code I have to send the birthday.
WebElement dob = driver.findElement(By.id("userDOB"));
dob.click();
String stringBirthday = "07241987";
char[] charsBirthday = stringBirthday.toCharArray();
for (char ch : charsBirthday) {
String userDob = Character.toString(ch);
dob.sendKeys(userDob);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
So I had to use the Actions class to try and replicate what a human would do.
Actions actions = new Actions(driver);
actions.moveToElement(dob).click();
actions.sendKeys(bday).perform();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.