Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendKeys() only passes partial value #2019

Closed
rschoenbichler opened this issue Apr 9, 2015 · 25 comments
Closed

sendKeys() only passes partial value #2019

rschoenbichler opened this issue Apr 9, 2015 · 25 comments

Comments

@rschoenbichler
Copy link

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.

@juliemr
Copy link
Member

juliemr commented Apr 10, 2015

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

@rschoenbichler
Copy link
Author

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

@tullmann
Copy link
Contributor

@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 #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.

@rschoenbichler
Copy link
Author

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

@zeropaper
Copy link

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.

@markharding
Copy link

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

@ghost
Copy link

ghost commented Nov 13, 2015

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.

@brocsk
Copy link

brocsk commented Nov 15, 2015

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

@juliemr
Copy link
Member

juliemr commented Nov 18, 2015

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

@ghost
Copy link

ghost commented Nov 26, 2015

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)...

@pgrm
Copy link

pgrm commented Feb 16, 2016

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.

@laurelnaiad
Copy link

👍 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}]

@matebordas
Copy link

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

@HFlorina
Copy link

HFlorina commented Apr 29, 2016

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

@Nez07
Copy link

Nez07 commented May 20, 2016

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.

@mona9301
Copy link

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

@diansan-zhou
Copy link

@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

@sdsanders
Copy link

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

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

@juliemr
Copy link
Member

juliemr commented Jun 21, 2016

All issues here are either a duplicate of #3003 or #3196 - I'm closing this issue to concentrate effort in those two.

@juliemr juliemr closed this as completed Jun 21, 2016
@djungowski
Copy link

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

@mikila85
Copy link

2.5 years and we are still waiting.... it is f$%#! not usable like this.

@JoannaG33
Copy link

Just implemented @sdsanders hotfix on an Angular Material form. It seems to be the only stable solution.

@aterrong
Copy link

aterrong commented May 29, 2018

Just in case anybody it's still facing this problem.
I'm using Selenium, Chrome and Mac but having the same problem.
After quite a few trial-and-error approaches what worked for me was introducing a tiny delay before entering the text.
Even if I tried char by char it didn't work for me.
It seems that the problem has to do (in my case) with these inputs:
<input placeholder="Value" type="text" id="xxxxxx" value="">
I could see that once I began typing there were a refresh were the placeholder reappeared, then cleared the input field and wrote the rest of the text
The slower you wrote the easier was to see this effect.
So I introduced this before start typing:
getClock().pauseFor(timeInMilliseconds);

@evanjmg
Copy link

evanjmg commented Jun 19, 2018

@aterrong could you elaborate on your solution? Where are you getting getClock?

danmichaelo added a commit to uio-library/bibrex that referenced this issue Jul 21, 2019
Drop IE11 testing for now because I cannot get SendKeys to work consistently. Every now and then, some random keys within a string will not be sent.

Some workarounds that could work:
- https://stackoverflow.com/a/43616117/489916
- angular/protractor#2019 (comment)
danmichaelo added a commit to uio-library/bibrex that referenced this issue Jul 21, 2019
Drop IE11 testing for now because I cannot get SendKeys to work consistently. Every now and then, some random keys within a string will not be sent.

Some workarounds that could work:
- https://stackoverflow.com/a/43616117/489916
- angular/protractor#2019 (comment)
danmichaelo added a commit to uio-library/bibrex that referenced this issue Jul 21, 2019
Drop IE11 testing for now because I cannot get SendKeys to work
consistently. Every now and then, some random keys within a string will
not be sent.

Some workarounds that could work:
- https://stackoverflow.com/a/43616117/489916
- angular/protractor#2019 (comment)
@IIIHeloIII
Copy link

IIIHeloIII commented Jun 30, 2020

Animations seem to be a problem.
I had this issue when opening a modal dialog (sendKeys only wrote the first 1 to 4 letters of my text). I noticed that disabling animations by using NoopAnimationsModule fixed the input issue.

Since I want to have animations I ended up with a fix where I assert that the dialog is ready for input by testing for the visibility of the modal without the ng-animating class on it (Xpath: //mat-dialog-container[not(contains(@Class, 'ng-animating'))]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests