protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Calling element.sendKeys() seems to not send all the keys

Open neosavvy opened this issue 12 years ago • 54 comments

I am doing the following two tests:

   it("Should be able to populate the firstname field", function () {

        expect(capturePageModel.findFirstNameFieldValue()).toEqual("");
        capturePageModel.setFirstNameFieldValue("Adam");
        expect(capturePageModel.findFirstNameFieldValue()).toEqual("Adam");

    });

    it("Should be able to populate the lastname field", function () {
        expect(capturePageModel.findLastNameField()).toEqual("");
        capturePageModel.setLastNameFieldValue("Parrish");
        expect(capturePageModel.findLastNameField()).toEqual("Parrish")
    });

When I execute both tests in the same describe block I definitely am seeing the second test only send the "sh" value of the "Parrish" value I am passing in. Thus the test fails.

However each test runs fine by itself. I am attempting to use PageObjects to write a few documents on how this could work but curious if you have seen anything like this happen.

Simple example of my setter and getter functions in my PageObjects

this.setLastNameFieldValue = function( value ) {

    var lastNameElement = element(by.model('presubmitUser.lastName'))
    lastNameElement.sendKeys( value );

}

this.findLastNameField = function() {
    var firstNameElement = element(by.id('lastName'))
    return firstNameElement.getAttribute('value');
}

The first name field is identical to the last name field.

neosavvy avatar Apr 11 '14 01:04 neosavvy

@hiteshAneja thanks for the info. In our case we were not using any modifier keys

dodoshanti avatar Mar 02 '16 09:03 dodoshanti

same issue,sendkeys typing first character only. using mocha 2.4.5 in windows 8.1 var emailTxt = driver.findElement(webdriver.By.name('Email')); driver.wait(emailTxt,10000); emailTxt.sendKeys("testing");

aniljogireddy avatar May 07 '16 20:05 aniljogireddy

Hi, I am encountering the same issue as described in this post:

Aaron-Hartwig commented on Dec 30, 2014 Having issues with sendKeys() where 5 is being treated as a backspace and 6 just terminates the process of sending keys to the input all together. Ex) elem.sendKeys(58801) would yield 8801 in the input elem.sendKeys(85801) would yield 801 in the input elem.sendKeys(88601) would yield 88 in the input

This is only happening when I run the tests from Jenkins, and does not occur when running on my local machine. What is a possible solution to this? Could it be something related to the Locale settings?

dwaned avatar May 30 '16 15:05 dwaned

We also only have this issue on jenkins and not locally...

svetozar02 avatar Jun 01 '16 18:06 svetozar02

I'm seeing this issue with the Microsoft Web driver (v 10586) on Edge - exactly the same test passes using Chrome driver. Windows 10 machine, Protractor Javascript.

For example, if I sendKeys("ABCDEFGHIJ") to an input text box, only some of the chars appear.

Ragnaar avatar Aug 23 '16 12:08 Ragnaar

Still exists. Site: http://maxcabrera.com/code/todo-list/ Protractor - 4.0.10 [15:53:15] I/status - selenium standalone version available: 2.53.1 [default] [15:53:15] I/status - chromedriver version available: 2.25 [default] [15:53:15] I/status - geckodriver version available: v0.11.1 [default] [15:53:15] I/status - android-sdk is not present [15:53:15] I/status - appium is not present NodeJS - 7

Test:

it('should create new note', function () {
        browser.get(URL)
        let webelement = $('input.enter-todo')
        webelement.clear()
        webelement.sendKeys('HHHHHHHHHHHHHHH')
        browser.sleep(2000)
        webelement.submit()

        let notes = $$('todo-list .small-12')

        browser.sleep(2000)
        //expect(notes.getText()).not.toContain('New Shiny note')
        expect(notes.getText()).toContain('HHHHHHHHHHHHHHH')
    })

Xotabu4 avatar Nov 11 '16 13:11 Xotabu4

I think that the issue might be related to keyup / keydown triggers. I got around the issue by introducing a helper function with a tiny delay after each character:

function controlledInsert( elm, txt, delay ) {
  for (var i = 0, len = txt.length; i < len; i++) {
    elm.sendKeys( txt[ i ] );
    browser.driver.sleep( delay );
  }
  elm.sendKeys(protractor.Key.NULL);
}

jlstrat avatar Feb 06 '17 16:02 jlstrat

I am also facing the same issue while testing mobile App but strange thing is that it is working on other pages correctly only on particular page it is behaving differently.

richashri87 avatar Mar 10 '17 13:03 richashri87

Found similar kind of issue when I upgraded my chrome to v57

prudvinath6 avatar Mar 16 '17 19:03 prudvinath6

I discovered keys like "@" and "." are not sent. Switching browser from Chrome to Firefox fixes the issue. This seems not related though, as alphanumerical input is still sent properly (string lenght does not matter).

Phoscur avatar Mar 25 '17 19:03 Phoscur

If it's helpful to others coming across this, I had this problem where sendKeys would consistently skip some characters. An ng-change that I have on the element that updates another element's value on the page (but does not change focus) caused the issue. Removing that ng-change fixed it. I need the ng-change so I used @dodoshanti 's 'blah'.split('').forEach((c) => element.sendKeys(c)) which fixed it for me (likely should actually do a .then if possible after each sendKeys(char) to make sure but works for me w/o it).

tonybranfort avatar Jun 16 '17 16:06 tonybranfort

Even I was facing the same problem. What i changed was instaed of using sendkeys i used setvalue.

Setvalue will be active when you use android element instead of web or mobile elemnt

palak1234 avatar Jun 28 '17 18:06 palak1234

@kuiro5 thanks a ton your solution work for me :D

Jayesh-raweng avatar Sep 06 '17 06:09 Jayesh-raweng

I have a text with . and @ I have to split them up [email protected]

await driver.elementByAccessibilityId('textUserName').sendKeys('[email protected]') textfield will show [email protected] I have to split them up in the code like this:

await driver.elementByAccessibilityId('textUserName').sendKeys('lay'); await driver.elementByAccessibilityId('textUserName').sendKeys('.mui'); await driver.elementByAccessibilityId('textUserName').sendKeys('[email protected]');

also I am not able to clear the textfield any one has any idea how I can clear the textfieldawait driver.elementByAccessibilityId('textUserName').clear() didn't work for me

LayMuiToh avatar Oct 25 '18 09:10 LayMuiToh