Selenium sendkeys with Chrome Driver drops character \"2\" and \"4\". Other characters are OK. When I use other browser (IE or FF), everything is OK.
code:
Investigating you are from Czech Republic also, I am going to make wild assumption, that your keyboard is set up to Czech as default.
I also had some strange issues with sendKeys
when my system had Czech keyboard as default one. Since I changed default to English, the problems dissapeared.
If this does not help, please provide info what is going to happen if you try this:
name.sendKeys("2");
name.sendKeys("22222222");
name.sendKeys("4");
name.sendKeys("44444444");
name.sendKeys("424242");
I had the same issue. I ended up calling sendkeys inside a loop until the correct value was inserted. Here's what I did:
WebElement name = driver.findElement(By.xpath(...));
this.sendkeys(name,"yourValue");
private void sendkeys(WebElement ele, String val) throws
InterruptedException
{ ele.clear();
while(true)
{ ele.sendKeys(val);
if(ele.getAttribute("value").equals(val))
break;
else
{ ele.clear();
Thread.currentThread();
Thread.sleep(3000);
}
}
Thread.currentThread();
Thread.sleep(3000);
}
Hope this helps.
I also experienced this problem when connecting to a VM using VNC and then running the Selenium test that way.
The VNC was actually the one dropping characters. Once I moved to a direct connection to the VM using the VirtualBox console... it worked fine.
It's an old question but still valid. I use Chrome Driver v2.53.
It looks like the keys are being send one by one to the browser (like a separate keyDown events). When it happens too fast then one of two results can be observable:
My solution is as follows:
protected void sendKeys(final WebElement element, final String keys) {
for (int i = 0; i < keys.length(); i++){
element.sendKeys(Character.toString(keys.charAt(i)));
waitUntil(attributeContains(element, "value", keys.substring(0, i)));
}
}
It is reliable and works fast enough. What is more, when we want to clear the input field before sending the keys then the same event shift can occur, e.g:
element.clear();
element.sendKeys("abc");
It is possible that the clear operation will happen in one of four places:
I recommend to always check if the operation we've just executed has been accomplished successfully, e.g.: when we want to clear the input field it's a good practice to:
It's a lot of operation to execute for a simple task. However, it will make the test more stable.