This issue may not be Protractor related but I'm not sure where else to look. My setup is using Protractor with jasmine-node to test an Angular front-end to a Rails app. When I try to get how many elements are found by protractor.findElements it always errors out.
My spec file follows the onJasmineNode example. So far I've tried the following:
ptor.findElements(protractor.By.css('.selector-string')).size();: [object object] has no method sizeptor.findElements(protractor.By.css('.selector-string')).count();: [object object] has no method countptor.findElements(protractor.By.css('.selector-string')).length;: undefined is not a functionFor fun I wrapped the findElements in a console.log and it returns this:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
Hi,
like all webdriver functions, findElements returns a promise. So, to get the length, you'll need to do
ptor.findElements(protractor.By.css('selector-string')).then(function(elems) {
var length = elems.length; // Here's your length!
});
Fantastic! Thank you so much. :smile:
It would be nice however it this would integrate well with jasmin matchers (https://github.com/pivotal/jasmine/wiki/Matchers), such that you could write:
expect(ptor.findElements(protractor.By.css('.selector-string'))).
toContain(3);
So apparently this video is incorrect at 25:40 by indicating you can simply use .length()?
https://www.youtube.com/watch?v=idb6hOxlyb8
Actually there are all kinds of things in that video that dont work? Im confused.
The .length bit is incorrect, not sure where that came from. element.all(...).count() should do the trick.
:+1: on the count() - thanks @juliemr
@juliemr in your example above it returns the length, but can you also use this to be able to use the .sendKeys() function to the element? Have an element inside a tab, inside a directive and this is the only piece of code thats sent anything back from it.
@EvanBurbidge Yes, you should be able to do a number of things with the element in the example above, including sendKeys().
Most helpful comment
Hi,
like all webdriver functions, findElements returns a promise. So, to get the length, you'll need to do