How to catch the <mat-error> error message text content using Protractor

佐手、 提交于 2020-07-22 05:53:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!