Selenium sendKeys are not sending all characters

删除回忆录丶 提交于 2019-12-02 22:26:44

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.

I stumbled upon this error when doing integration tests with NightwatchJS (which uses selenium).

So I'm writing this for people coming here in the future.

I wrote this extension command for nightwatch:

exports.command = function (selector, value, using) {
    var self = this;
    self.elements(using || 'css selector', selector, function (elems) {
        elems.value.forEach(function (element) {
            for (var c of value.split('')) {
                self.elementIdValue(element.ELEMENT, c);
            }
        });
    });
    return this;
};

Which can be used in this way:

var username = 'integration@test.com';
browser.setValueSlow('input[ngcontrol=username]', username); //Works with ng2!

This issue was also discussed on NightwatchJS's github here

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.

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);
}

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");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!