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?
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:
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')
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With