问题
I'm dealing with below element and having trouble with getting the error message text in to a variable.
<mat-error _ngcontent-c16="" class="mat-error ng-star-inserted" id="error-email-required" role="alert" style=""> Email is a required field </mat-error>
Catching the element is straight forward.
var emailReqiredLabel = element(by.id('error-email-required'));
I tried below options but all printing as >> visible error message is : [object Object]
var errormsg = emailReqiredLabel.getText().toString();
var errormsg = emailReqiredLabel.getAttribute('value').toString();
console.log("visible error message is : " + errormsg );
can someone advice please.
回答1:
mat-error does not show up by default. It only shows when the input is touched. So before getting the text try to click on the field and try getText(). If that does not work try JSON.Stringify(errormsg).
来源:https://stackoverflow.com/questions/52361190/how-to-catch-the-mat-error-error-message-text-content-using-protractor