protractor: Calling element.sendKeys() seems to not send all the keys
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.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 56 (14 by maintainers)
another workaround: pass individual chars to sendKeys:
'blah'.split('').forEach((c) => element.sendKeys(c))
We also only have this issue on jenkins and not locally…
@dodoshanti , @foch The problem is happening because a previous test is using the modifier keys and the modifier keys are not released.
By Design the modifier (SHIFT, CONTROL, ALT, META) keys are stateful, and once they are pressed, they remain in pressed state unless
So the easiest solution is to use these keys like this
Very well explained here: webdriver.WebElement.sendKeys
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
However if I run it on Windows rather than Linux (via Sauce Labs) it works just fine. I think they keys are mapped differently for whatever version of Linux Sauce is using and that was my issue.
Had the same issue. Somehow by calling element.clear() before element.sendKeys(), even if the input was initially empty, solved it for me.
Found similar kind of issue when I upgraded my chrome to v57
haha, I wish I could send you a link. But, its my company’s proprietary app. You know how it goes. I think there may just be a race condition I can pin down. I put in a sleep and that works…but that wont make it past code review! 😃
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.
Innumerable permutations of
sendKeys()
failed, so I worked around the failing-on-Saucelabs issue like so: