5

According to Protractor Angular 2 Failed: unknown error: angular is not defined angular selectors by.model are not supported.

I also went to http://www.protractortest.org/#/ and I noticed that seems that no change was made to fix this.

How can I set an input text using protractor and Angular 2?

EDIT

I can select my by making this:

let myelement: ElementFinder = element(by.css('.text-input'));

But I have several inputs on my html page. How can I have the 4th ion-input, per example?

Community
  • 1
  • 1
Goldbones
  • 1,407
  • 3
  • 21
  • 55
  • Could you show how your input looks like in HTML? Thanks. – alecxe Jun 23 '16 at 17:00
  • Angular-seed did setup protractor, maybe it helps https://github.com/mgechev/angular2-seed/blob/master/src/client/app/%2Bhome/home.component.e2e-spec.ts – null canvas Jun 23 '16 at 17:02

2 Answers2

3

But I have several inputs on my html page. How can I have the 4th ion-input, per example?

You can issue element.all() and use .get(index) to access an element by index:

let myelement: ElementFinder = element.all(by.css('.text-input')).get(3);  
myelement.sendKeys("text");

Note that we use 3 since indexing is 0-based.

You can also make use of a convenient shortcut for CSS selectors:

let myelement: ElementFinder = $$('.text-input').get(3);
myelement.sendKeys("text");

FYI, negative indexing is also supported in case you want to get elements from the other end:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

Protractor allows you to use the element.all function which returns an array of objects.

So for your particular example you could do something like this put inside of your test case:

    element.all(by.css('.text-input')).then(function(elements) {
       elements[3].sendKeys('some text')
    });
Jarod Moser
  • 7,022
  • 2
  • 24
  • 52