Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
how to get count of child elements using selenium web-driver for nodejs

I have searched at numerous places but I am not getting an answer

here is my html :

    <form id="search_form_homepage" >
    ...
<div class="search__autocomplete" style="display: block;">
    <div class="acp-wrap js-acp-wrap">
        <div class="acp" data-index="0"><span class="t-normal">elephant</span>cheap auto</div>
        <div class="acp" data-index="1"><span class="t-normal">elephant</span>asia</div>        
        ...
        ...
        <div class="acp" data-index="2"><span class="t-normal">elephant</span>africa</div>
    </div>
    ...
</div>
</form>

I simply need to get the count of the <div> present within the div with class acp-wrap js-acp-wrap

I can reach this point but am stuck beyond :

let xyz = driver.findElements(By.className(".acp-wrap js-acp-wrap>div"));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You would need to use By.css to get element by this: .acp-wrap js-acp-wrap > div. Also, your selector is not correct. When you select an element by class, you need to put a period before the class name: .acp-wrap.js-acp-wrap > div (remove the space between acp-wrap and js-acp-wrap, too).

Here is how you can get that element now:

let xyz = driver.findElements(By.css(".acp-wrap.js-acp-wrap > div"));

Now to get the count, you can get the length property of xyz. But since driver.findElement returns a promise, you need to use async-await. You can create a function:

async function getCount() {
  let xyz = await driver.findElements(By.css(".acp-wrap.js-acp-wrap > div"));
  const count = xyz.length;
  return count;
}

EDIT

When you call the function:

getCount().then(function(count) {
  // your stuff there
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!