Expecting Null equal to 'Some Value' in Protractor



  • 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



  • 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')
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2