8

I am new to ProtractorJS. What I am trying to do is trying to get the value of a disabled input element. This input element is bound to a model. Initially this input element is empty; then after some action the model value is updated (and thus displayed in input element). I need to get that value, how can I do that ?

My input element is:

<input class="form-control ng-pristine ng-valid" style="font-size: 11px;" disabled="disabled" type="text" ng-model="Promotion.PrometricID">

I am trying to fetch value by:

element(by.model("Promotion.PrometricID")).getAttribute('value');

But whenever I write the value in console it gives me "[object] [object]".

Can anyone please tell me how to find value in this text box or in model ?

Eric Schmidt
  • 312
  • 1
  • 11
Sumit
  • 2,932
  • 6
  • 32
  • 54

4 Answers4

22

It is just because getAttribute() returns a promise.

You need to resolve it if you want to see the result on the console:

var elm = element(by.model("Promotion.PrometricID"));
elm.getAttribute('value').then(function (value) {
    console.log(value);
});

FYI, exploring The WebDriver Control Flow documentation page should clear things up.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

this way worked for me:

element(by.binding('Promotion.PrometricID')).getText().then(function (value) {
                console.log(value);
            })
Luis Kimura
  • 136
  • 1
  • 3
0

My solution:

element(by.model('Promotion.PrometricID')).getText().then(function (value) {
    console.log(value);
});
Bwyss
  • 1,736
  • 3
  • 25
  • 48
0

Same as the rest except with await

let text = await element(by.binding('Promotion.PrometricID')).getText();
console.log(text);
Stucco
  • 388
  • 5
  • 21