protractor icon indicating copy to clipboard operation
protractor copied to clipboard

sendKeys() only passes partial value

Open rschoenbichler opened this issue 11 years ago • 25 comments

After upgrading to protractor 2.0 my login tests started failing.

In my PO I use the following function to handle input values:

    function _input(parentElement, binding, value) {
        var field = parentElement.element(by.model(binding)).element(by.css("input"));
        if (value === undefined)
            return field.getAttribute('value');
        else
            return field.clear().then(function() {
                return field.sendKeys(value);
            });
    }

I found out that sendKeys only passes the first part of the value (always with a different length, sometimes one character sometimes n-1). Even if I make a conditional wait for the input to contain the whole value, the condition never gets fullfilled. It seems like sendKeys randomly stops sending keys from the value.

rschoenbichler avatar Apr 09 '15 04:04 rschoenbichler

Can you tell us your browser version, version of webdriver, and OS?

juliemr avatar Apr 10 '15 19:04 juliemr

Sure, I'm using:

  • current stable chrome (atm 41.0.2272.118)
  • windows 7
  • not shure which webdriver-version that is exactly, but webdriver-manager status says chromedriver is up to date

rschoenbichler avatar Apr 12 '15 04:04 rschoenbichler

@kleinerroemer are you using a non-English keyboard or remote display or any other configuration that might confuse the keyboard mappings? Chromedriver has had some problem configurations where it drops characters out of sendKeys. See https://github.com/angular/protractor/issues/698 and http://stackoverflow.com/questions/18483419/selenium-sendkeys-drops-character-with-chrome-driver and https://code.google.com/p/chromedriver/issues/detail?id=1037 (the non-English keyboard bugs seem to be fixed recently, though.)

Alternatively, the bug might be in the code after your _input method (if that is not waiting for the sendKeys to complete somehow.

tullmann avatar Apr 12 '15 15:04 tullmann

my keyboard layout is set to german but switching to english layout didn't change anything. sendKeys always skips the keys at a different point. I don't use remote display.

I doubt that the bug is in my method, since it worked just fine before upgrading. My current workaround looks like this:

    function _completeInput(field, value) {
        return field.getAttribute('value').then(function(v) {
            if (v.length < value.length) {
                return field.sendKeys(value.substring(v.length, value.length)).then(function() {
                    return _completeInput(field, value);
                });
            }   
        });
    }

rschoenbichler avatar Apr 13 '15 04:04 rschoenbichler

It looks like we have a similar issue here.

On the install of a colleague (windows 7, protractor 1.5, chrome 42.0.2311.90) everything is fine. On my machine setup (ubuntu 13.10, protractor 2.0.0, chrome 42.0.2311.90 (64-bit)) the exclamation mark (!) will not be entered by sendKeys(). I did a downgrade to protractor 1.8.0, but the problem was still occurring. I did a second downgrade to 1.5 (to match my colleague's version). My colleague did an upgrade to protractor 2 (on his windows machine).

From what we could observe, the problem does not seems to happen on a windows machine (there's always a first time) but on ubuntu, whatever the version is, it happens all the time. I hope it will help to spot the issue.

zeropaper avatar Apr 28 '15 12:04 zeropaper

I am still getting this problem, particularly in chrome. It seems totally random - sometimes it works and sometimes it doesn't.

eg:

element(by.id('message')).sendKeys(Date.now());

will not output the current timestamp, but something like 1142

markharding avatar Nov 05 '15 10:11 markharding

I experience this is well. In my case, the tested application is based on Angular 2 and it happens only with the input elements that are bound to a model [(ng-model)] and only if the string is long enough (in my case e.g. "credentials.password"). If they are not bound, everything is ok. My current workaround is (in TypeScript):

export function sendKeys(element:protractor.ElementFinder, string:string):void {
  "use strict";

  for (let i:number = 0; i < string.length; i++) {
    element.sendKeys(string.charAt(i));
  }
}

but it significantly slows down the tests.

ghost avatar Nov 13 '15 21:11 ghost

I'm also experiencing this issue now.

Upgrading tests from 1.8.0 to 2.5.1. I have some tests randomly failing now that used to work. These are on a page where browser.ignoreSynchronization = true;

I will do something like:

input1.sendkeys('abc'); input2.sendkeys('def');

I will either see this:

Input1: 'ab' Input2: 'cdef'

or

Input1: 'abcdef' input2; ''

Using Chrome: Version 46.0.2490.86 m

brocsk avatar Nov 15 '15 23:11 brocsk

@brocsk @radek-holy are either of you able to create a reproducible case we can test against using http://www.protractortest.org/testapp/?

juliemr avatar Nov 18 '15 04:11 juliemr

No, sorry, I am not able to reproduce it against the Testapp. Here is the simplest reproducer I am able to come up with: http://plnkr.co/edit/f0LQ0zLvtr8HEodySl35 . For some reason, it's necessary to call sendKeys twice to hit the issue. I'm sorry if this is another issue (e.g. Angular 2 specific)...

ghost avatar Nov 26 '15 13:11 ghost

I've encountered a similar issue with 48.0.2564.109 (Official Build) m (32-bit) on Windows 10 x64. I've switched to Firefox for running the tests in the meanwhile, and didn't encounter this issue yet.

I'm running my tests so far on non-angular pages with browser.ignoreSynchronization = true;

I'm currently working on reproducing the problem on the testapp.

Update - I didn't manage to reproduce it with the testapp. And I actually have maybe a different issue because for me the first part is missing and the last characters show up. Always after few reloads of the browser. However this problem persists even when I ensure that the element is being displayed:

elem.isDisplayed();
elem.clear();
elem.sendKeys('custom input')

and when I add a browser.sleep after the page has been loaded. And it doesn't show up with firefox.

My current workaround is now:

public setValueOnInputElement(inputElement: protractor.ElementFinder, value: string) {
  inputElement.clear();
  inputElement.sendKeys(value);

  return inputElement.getAttribute('value')
    .then(insertedValue => {
      if (insertedValue !== value) {
        return this.setValueOnInputElement(inputElement, value);
      } else {
        return null;
      }
    });
}

This sets the correct value eventually.

pgrm avatar Feb 16 '16 12:02 pgrm

:+1: Thank you for the workaround @pgrm!

This problem was hitting me probably about 8 times out of 10 on the first test in my suite.

FWIW, my platform below.

    Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17'
    System info: host: 'MacPro-3362', ip: '10.0.0.81', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_45'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/qv/5y3z61z52ng0tgtffc5fmc24zcqrgw/T/.org.chromium.Chromium.4RbZiA}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.87, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

laurelnaiad avatar Mar 17 '16 03:03 laurelnaiad

I'm experiencing the same issue as @radek-holy described on Angular 2 with input fields.

matebordas avatar Apr 15 '16 12:04 matebordas

I spent a whole day trying to figure out why my tests were suddenly failing. This workaround fixed all my troubles. Thank you !

HFlorina avatar Apr 29 '16 15:04 HFlorina

I am not using Angular 2. I have protractor 3.0.0. My input fields on login screen no more work! SendKeys() don't seem to work at all. even clear() does not work on the inputs. I get an error invalid element state: element must be user-editable in order to clear it. I actually click() the input before trying to clear it. The second issue with clear() is secondary. I am also facing the same issue with sendKeys() not working. MY chrome recently updated to version 50.0.2661.102 m. Unfortunately this workaround does not work for me.

Nez07 avatar May 20 '16 08:05 Nez07

Hi,

Try with below example,

inputUsername.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "a")); inputUsername.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "x")); browser.sleep(1000); inputUsername.sendKeys(username);

Here instead of clear(), we can use "inputUsername.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "x"));"

mona9301 avatar May 20 '16 08:05 mona9301

@juliemr I have the similar problem, and I am able to consistently reproduce it in the testapp link you mentioned above In the elementexplorer, I typed command: screen shot 2016-05-26 at 2 56 34 pm I expected the character 5 will be appended after "Anon" (to be "Anon5"), but in fact, it deleted the last character of "Anon": screen shot 2016-05-26 at 3 00 02 pm Then I tried sending another string and got this: screen shot 2016-05-26 at 3 01 58 pm It looks like the character 5 is misinterpreted to backspace... and the similar misinterpretation happened to charactor 6 (move cursor to the next button or textbox, similar to the function of tab).

Here is the environment I used: Chrome: 50.0.2664.102 (64-bit) ChromeDriver: 2.21.371461 Selenium: 2.45.0 Protractor: 2.0.0

diansan-zhou avatar May 26 '16 22:05 diansan-zhou

Splitting up the string seems to fix the issue for me, for example:

emailAddress.split('').forEach((c) => emailField.sendKeys(c));

sdsanders avatar Jun 02 '16 19:06 sdsanders

All issues here are either a duplicate of https://github.com/angular/protractor/issues/3003 or https://github.com/angular/protractor/issues/3196 - I'm closing this issue to concentrate effort in those two.

juliemr avatar Jun 21 '16 22:06 juliemr

Two years later and @sdsanders' hotfix is still the way to go

djungowski avatar Feb 16 '18 16:02 djungowski