Hi,
So I'm running into an issue where I'm trying to loop through all of the input fields on the page, clear the input for them, and then update them with a value. Here's the essential code:
element.all(by.model('part.quantity')).each(function(part_q){
part_q.clear().then(function(){
part_q.sendKeys("1");
});
}).then(function(){
...
}
This issue varies in scope (i don't mean the angular kind), but say I have 7
<input ng-model='part.quantity'> 's on the page that i'm testing. When i run my test with the code above it goes through each input and clears all of them and updates them all with the value 1, except for the first 2 input fields. In the first 2 fields it clears, but it adds the value 1 to them twice. So say I have these values before running the test:
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
<input ng-model='part.quantity' value="4">
afterwards those values will become
<input ng-model='part.quantity' value="11">
<input ng-model='part.quantity' value="11">
<input ng-model='part.quantity' value="1">
<input ng-model='part.quantity' value="1">
<input ng-model='part.quantity' value="1">
<input ng-model='part.quantity' value="1">
<input ng-model='part.quantity' value="1">
but the expected result for all of the values is 1.
This changes if i have five elements. If i have five it only doesn't work for the first input field, but it works for the next 4. I've tried various solutions (different locators (e.g. by.css), or running through a recursive while loop such as:
$$('.part-quantity').count().then(function(num_parts){
var idx = 0;
function alterQuantity() {
while (idx < num_parts){
$$('.part-quantity').get(idx).then(function(part_q){
part_q.clear().then(function(){
var rand_num = utils.randomIntFromInterval(2, 10).toString();
part_quantities.push(rand_num);
part_q.sendKeys(rand_num).then(function(){
idx++;
alterQuantity();
});
});
});
}
}
});
or running using filter() instead of each():
$$('.part-quantity').filter(function(part_q, idx){
return part_q.clear().then(function(){
var rand_num = utils.randomIntFromInterval(2, 10).toString()
part_quantities.push(rand_num)
console.log(rand_num);
browser.sleep(2000);
return part_q.sendKeys(rand_num);
});
}).then(function(quantity){
console.log(part_quantities);
});
but the filter() i used and the each() functions function identically. The recursive thing doesn't really work (i didn't spend too much time on it since I didn't really see too much promise in it working any better). This seems like a webdriver thing but I've hit a wall at this point and don't know what to do. I don't know if I need to be utilizing promises better? Any help would be appreciated.
Thanks.
edit: I've tested with both chrome and firefox drivers and the same thing happens
So I tried doing the following:
element.all(by.model('part.quantity')).each(function(part_q) {
part_q.click().sendKeys(protractor.Key.chord(protractor.Key.COMMAND, "a"));
part_q.click().sendKeys(protractor.Key.BACK_SPACE);
part_q.sendKeys("1");
});
but then I ran into issues with both chrome and firefox testing. In firefox it wouldn't clear the value, but it would add the 1 (although i think it would only add the 1 once). In chrome I would occasionally get this error Failed: unknown error: Element is not clickable at point.
I'm pretty sure this is due to https://github.com/SeleniumHQ/selenium/issues/444
Which will be fixed in the next selenium-webdriver release.
ok I will wait to test with the next selenium release and then report back with whether or not that fixes it
Any updates on this?
@SirNeuman were you able to get this working?
Closing as obsolete.
@juliemr Why is this obsolete? Is there a better method to do this? or was there a fix?
Hi, I'm facing same issue without element.all.each() loop.There are two input fields and I'm clearing both fields and then filling value respectively as 12.34 and for next field 1.25 but sometimes it fills 1,252.34 in the first field and test case is failing.This issue is occurring intermittently.
Is there any update on this?