1

I enter the value with this code:

var FirstName = element(by.name('firstName'));
FirstName.clear().sendKeys('RM'); 

The code updates the profile of the user correctly.

Now I am trying to read that value or expecting that value in Protractor Visual Studio Code with this code:

expect(element(by.name('firstName')).getText()).toEqual('RM');

I have also tried this:

expect(FirstName.getAttribute('firstName')).toEqual('RM'); 

but it returns a null value

How do I read the value of the First Name field?

The app code is below. r

2
  • 1
    Please, reformat your question so it is clear what is the problem. meta.stackexchange.com/help/how-to-ask Aug 9 '19 at 10:42
  • Try to formulate like this: 1- Context: What type of application you are dealing with. 2 - Goal: What do you want to accomplish. 3 - What you have tried. 4 - The problem that you experienced with your attempt. Aug 9 '19 at 11:03
1

Protractors getAttribute('firstName') gets the value of the attribute firstName, not the value of the input. Your example element does not have an attribute "firstName". It has attributes id, pattern, name, placeholder, aria-*, etc..

I think you want to use the (in your case hidden) attribute 'value' instead:

FirstName.getAttribute('value')
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.