web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Count webpage elements...
Power Automate
Unanswered

Count webpage elements by CSS selector

(0) ShareShare
ReportReport
Posted on by 20

Is there a way to count all the elements in the webpage that contain this css selector:

xmi5d70 x1fvot60 xo1l8bm xxio538 xbsr9hj xuxw1ft x6ikm8r x10wlt62 xlyipyv x1h4wwuj xeuugli xh8yej3

 

The thing is, most of them are hidden, you need to constantly scroll down for the elements to appear so you can count them.

How to get the count of all the elements with this selector, hidden or not?

I have the same question (0)
  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @FlashDota 

     

    Please take a look at the JavaScript code provided below, which is an example of how to retrieve the number of rows from a table on an online sample website. Afterwards, we can adapt and refine the code for use on your website.

     

    Deenuji_0-1713151756736.png

     

    Flow source code:

    WebAutomation.LaunchChrome.LaunchChrome Url: $'''https://afd.calpoly.edu/web/sample-tables''' WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 PiPUserDataFolderMode: WebAutomation.PiPUserDataFolderModeEnum.AutomaticProfile BrowserInstance=> Browser
    WebAutomation.ExecuteJavascript BrowserInstance: Browser Javascript: $'''function ExecuteScript() {var rowCount;
    
    // Define a function to count rows
    function countRows(container) {
     // Initialize a counter
     rowCount = 0;
    
     // Check if the container exists
     if (container) {
     // Find all elements with role=\"row\" within the container
     var rows = container.querySelectorAll(\'tbody tr\');
    
     // Count the number of elements found
     rowCount = rows.length;
     }
    
     // Return the count
     return rowCount;
    }
    
    // Call the countRows function with the container variable as an argument to update the global variable rowCount
    countRows(document.querySelector(\'.table_directory tbody\')); 
    
    return rowCount;}
    
    
    
    
    
    
    
    
    
    
    
    ''' Result=> Result

    How to copy/paste above code into your PAD?

    Deenuji_1-1713151757125.gif

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     
  • FlashDota Profile Picture
    20 on at

    Hi @Deenuji thanks very much for replying.

    For some reason I can't copy paste the flow (it's not pasting into PAD) so I just copied the javascript function exactly how you wrote it and ran it on the webpage.

    It is returning [object Object]

     

    Also, I don't understand what is the Result=>Result in the end, so I don't know how to make that step in PAD

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @FlashDota 

     

    Please Launch your browser with below link:

    https://afd.calpoly.edu/web/sample-tables

    Deenuji_0-1713181103061.png

     

    And Use Run JavaScript function on web page

    Deenuji_1-1713181153848.png

     

    Javascript code:

    function ExecuteScript() {
    
    var rowCount;
    // Define a function to count rows
    function countRows(container) {
     // Initialize a counter
     rowCount = 0;
     // Check if the container exists
     if (container) {
     // Find all elements with role=\"row\" within the container
     var rows = container.querySelectorAll('tbody tr');
     // Count the number of elements found
     rowCount = rows.length;
     alert(rowCount);
     }
     // Return the count
     return rowCount;
    }
    // Call the countRows function with the container variable as an argument to update the global variable rowCount
    countRows(document.querySelector('.table_directory tbody')); 
    return rowCount;
    }

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

  • FlashDota Profile Picture
    20 on at

    @Deenuji I ran that script on the webpage, it returned 4.

    I'm not really sure how to implement that answer to my request, since I don't really use javascript

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @FlashDota 

    If your organization permits, you can simply right-click on the browser, select "View Source," and then copy all html code and share the content with us. Highlight the specific data you wish to count, and we will provide assistance accordingly.

     

    Before sharing the content in a public forum, please ensure that all sensitive data is hidden or removed.

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 308 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 171 Super User 2026 Season 2

#3
Haque Profile Picture

Haque 137 Super User 2026 Season 2

Last 30 days Overall leaderboard