How to get tags values in Protractor?



  • // Find an element using a css selector.
    by.css ('. myclass')
    
    // Find an element with the given id.
    by.id ('myid')
    
    // Find an element with a certain ng-model.
    // Note that at the moment, this is only supported for AngularJS apps.
    by.model ('name')
    
    // Find an element bound to the given variable.
    // Note that at the moment, this is only supported for AngularJS apps.
    by.binding ('bindingname')
    

    For example I am doing authorization (empty fields) and want to check if the text is displayed or not.



  • Tags can be referenced as follows:

    element (by.tagName ('a'))
    

    or

    $ ('a')
    

    If you need to check the text inside the tag for compliance:

    expect (element (by.tagName ('a')). getText ()). toEqual ('text');
    

    or

    expect ($ ('a'). getText ()). toEqual ('text');
    

    Getting the text itself:

    $ ('a'). getText (). then ((text) => {
        console.log (text);
    })
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 4