question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to get number of elements returned by `findElements`

See original GitHub issue

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 size
  • ptor.findElements(protractor.By.css('.selector-string')).count();: [object object] has no method count
  • ptor.findElements(protractor.By.css('.selector-string')).length;: undefined is not a function

For fun I wrapped the findElements in a console.log and it returns this:

{ then: [Function: then],
  cancel: [Function: cancel],
  isPending: [Function: isPending] }

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
juliemrcommented, Jul 10, 2013

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!
});
2reactions
juliemrcommented, Mar 1, 2014

The .length bit is incorrect, not sure where that came from. element.all(...).count() should do the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the number of elements found using Selenium ...
Try driver.find_elements_by_xpath and count the number of returned elements.
Read more >
FindElements in Selenium – FindElement by XPath - Guru99
It returns an empty list if there are no elements found using the given locator strategy and locator value. Below is the syntax...
Read more >
How to return the number of elements present in the website?
Example: In a page, some elements have text = 'coach 1'. I want to count all elements have this text but I don't...
Read more >
findElement vs findElements in Selenium - BrowserStack
The findElements command returns an empty list if no elements are found using the given locator strategy and locator value. Below is the...
Read more >
Selenium findElement and findElements Examples
Selenium findElements command takes in By object as the parameter and returns a list of web elements. It returns an empty list if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found