Reputation: 41
How to find the text "VAT Number is required."?
I tried with:
err = element(by.css('.invalid error-msg')).getAttribute();
expect(err.getText()).toEqual('VAT Number is invalid.');
<em class="invalid error-msg">
<div> VAT Number is required.</div>
</em>
Upvotes: 0
Views: 364
Reputation: 2375
You were almost there, the code should be
err = element(by.css('.invalid.error-msg'));
expect(err.getText()).toEqual('VAT Number is invalid.');
The getAttribute()
will only the the value of an attribute, see here so you need to leave it out. You only use it when you need to know for example the href
-value of a link, or the class
of a specific element.
In your case you want to verify the text in an element, so it should be the above syntax, see also here
Upvotes: 1
Reputation: 2547
You can use below code.
var EC=protractor.ExpectedConditions;
var errWebElement = element(by.css('.invalid.error-msg'));
expect(errWebElement.getText()).toEqual("VAT Number is required.");
**OR**
expect(EC.visibilityOf(errWebElement)).toBe(true);
Upvotes: 0