I\'m using Java, Selenium, and Chrome for test automation. Our developers recently upgraded our UI from AngularJS to Angular2 (not sure if that matters). But since then, sendKey
This is due to a bug in Angular apps. Workaround is to put a sleep function.
public void setText(By element, String text) {
sleep(100); // Angular version < 2 apps require this sleep due to a bug
driver.findElement(element).clear();
driver.findElement(element).sendKeys(text);
}
I assume this is caused by this Angular2 issue https://github.com/angular/angular/issues/5808
Angular can't process input events when they arrive too fast.
As a workaround you would need to send single characters with a small delay between each.
Using
the behavior also occurs and is even worse: I see that the character is typed in and suddenly after that it disappears. A workaround is to be persistent and just try it again. And again. Until the character is finally typed in.
// Type in every single character
for (int i = 0; i < textToType.length(); i++) {
boolean typingCharacterWasSuccessful = false;
// If typing was not successful before, just type again
while (!typingCharacterWasSuccessful) {
// Type in the character
char singleCharacterToType = textToType.charAt(i);
htmlTextfeld.sendKeys(Character.toString(singleCharacterToType));
// Wait a little. Maybe alternatively/additionally wait.until(...)
Thread.sleep(200);
// Check typed in string.
String inputValueAfterTyping = htmlTextfeld.getAttribute("value");
if (inputValueAfterTyping.length() > i + 1) {
// Alternatively: delete everything and start all over
throw new Exception("Input value too long. Maybe character typed in twice!?");
}
// Typing was successful if the value in the input field is as expected (up to now)
typingCharacterWasSuccessful
= inputValueAfterTyping.equals(textToType.substring(0, i + 1));
}
}
I was getting this error too in Java, Selenium. You might also be getting this error too while writing your codes - "sendKeys (CharSequence) from the type Webelement refers to the missing type charSequence"
I tried varying the wait time and even typing extra characters before the main characters, they did not work.
The simple trick I used was to change the Java Compiler version from JRE 9 to JRE 10.
i had the same problem, if you see it carefully selenium is changing the characters, some numbers perform a backspace or other symbols, i read it happens when using selenium with vncserver, i changed to firefox.... and it worked.
if that's not your problem, maybe sending the data in parts:
input1="Joh201605130947AM"
txtFirstName.sendKeys(input1[0:7])
txtFirstName.sendKeys(input1[8:end])
try this code.. other way to set values using javascript WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');"); driver.findElement(By.xpath("//input[@name='body']")).clear(); driver.findElement(By.xpath("//input[@name='body']")).sendKeys("Ripon: body text");