0

I am testing a form in Angular 9, and I want to check if any error messages are displayed using Protractor 5.4.3. Error messages are shown according to an *ngIf.

Outside the test, the code works normally.

If I do the search as the official documentation recommends, there is no element:

const elements = await element.all(by.css('.my-class')).getWebElements();

But if I do it this way, the result is returned correctly:

const elements = await browser.findElements(by.css('.my-class'));

Although my test works using the second solution, I would like to understand what the difference is between the two, and what I'm doing wrong so the first way doesn't work. Could anyone explain? Thanks.

Ps: As I understand it, the two forms would be equivalent, because according to official documentation, it would be just syntactic sugar. But there is obviously some difference between them, since only one works for me, or else it is a bug.

  • what does just element.all show? – JWP Apr 07 '20 at 00:38
  • An empty array [] – Vinícius Bastos Apr 07 '20 at 02:01
  • Is there a reason you want the base webelement object from webdriverJs as opposed to the element finder? ([See this answer](https://stackoverflow.com/questions/39026997/difference-between-element-and-element-getwebelement-in-protractor)). Also I don't see any reference to the method `getWebElements` plural. Can you indicate where you learned of that method? – DublinDev Apr 07 '20 at 07:17
  • "await element.all(by.css('.my-class'))" also returns an empty array, with .count() == 0, I used .getWebElements() to both return the same result type. This method is suggested by intellisense, is on [this link](https://www.protractortest.org/#/api?view=ElementArrayFinder) and in articles on the web. – Vinícius Bastos Apr 07 '20 at 18:34

0 Answers0