Retrieve the total count of rows present in a specific table

Is there a way to accurately determine the number of rows in a table? I've attempted multiple methods (all unsuccessful) and this is my latest attempt:

  var _tableOfInterestsCount = wait.Until(x => x.FindElements(By.XPath("//*[@id='gridBodyTable']/tbody")));
        var  _trs = wait.Until(x => x.FindElements(By.XPath(".//tr[@class = 'ms-crm-List-Row']")));

While debugging, I'm consistently getting Count = 1 even though there are actually 3 rows. All three tr's have the same class. Additionally, there's an attribute in the table itself that states: numrecords="3" Yet, when I try to access this value, it also returns a count of 1 instead of 3.

var _tableOfInterestsCount = wait.Until(x => x.FindElement(By.XPath("//*[@id='gridBodyTable']")).GetAttribute("numrecords"));

Here is the relevant HTML code snippet:

<table class="ms-crm-List-Data" cellspacing="0" cellpadding="1" rules="rows" morerecords="0" totalrecordcount="3" allrecordscounted="1" oname="10046" numrecords="3" tabindex="0" primaryfieldname="new_name" summary="foo" border="1" id="gridBodyTable" style="border-style:None;border-collapse:collapse;">
<colgroup><col width="18px" class="ms-crm-List-CheckBoxColumn"><col width="302" name="new_name" class="ms-crm-List-DataColumn ms-crm-List-SortedColumn"><col width="127" name="createdon" class="ms-crm-List-DataColumn"><col></colgroup><thead><tr class="ms-crm-Hidden-List"><th scope="col" class="ms-crm-Hidden-List"></th><th scope="col" class="ms-crm-Hidden-List">שם</th><th ...etc

EDIT: Interestingly enough, with only 2 rows, the count shows as 0. I even attempted the following approach, still resulting in the incorrect attribute value:

 Dictionary<string, object> attributes = executor.ExecuteScript("var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items...

Answer №1

Instead of using xpath to access the table, why not leverage the Id attribute?

 var _tableOfInterestsCount = Driver.FindElement(By.Id("gridBodyTable"));
 List<IWebElement> _trs = _tableOfInterestsCount.FindElements(By.ClassName("ms-crm-List-Row")).ToList();
 int count = _trs.Count();

If this approach doesn't yield results, please provide the HTML code for the rows.

Answer №2

Perhaps you could consider attempting the following approach:

findElements(By.xpath(".//div/table/tbody/tr")).size()

Answer №3

Regrettably, I encountered a challenge where the solution required switching to a different frame before locating the desired element.

_webdriverIE.SwitchTo().Frame(_webdriverIE.FindElement(By.XPath(".//iframe[@id='area_new_contact_new_contact_contentFrame']")));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Efficiently organizing dates in the Vuetify date range picker

I am working with a vuetify date range picker component and have the following code: <v-menu ref="effectiveDateMenu" v-model="effectiveDateMenu" :close-on-content-cl ...

Save and showcase SQL, PHP, HTML, and JS code exactly as it is preserved in MYSQL database

Is there a way to store and display complete JS, PHP, and HTML code in MySQL without altering the format? The stored PHP code should appear as: <?php echo "something"; ?> And not just: something For JavaScript: <script> document.write(&ap ...

How to deselect a checkbox in next.js when another one is selected

I'm looking to create a navigation system where clicking on a button scrolls to a specific section. However, I'm wondering how to deselect three inputs when one is selected in next.js using the code below. Do I need to modify each menu item indiv ...

How to showcase information stored in Firebase Realtime Database within an Ionic application

Looking to list all children of "Requests" from my firebase realtime database in a structured format. Here's a snapshot of how the database is organized: https://i.stack.imgur.com/5fKQP.png I have successfully fetched the data from Firebase as JSON: ...

The PHP code embedded within the HTML document and triggered by an AJAX request failed to

Here is an example of my ajax call: function insertModal(link) { $.ajax({ url: link, cache: false, dataType: "text", success: function(data) { $("#modalInput").html(data); }, error: function (request, status, error) { ...

Having trouble creating an alias system in discord.js and encountering errors

While developing an alias system for my Discord bot, I encountered a situation where I wanted to display the message: "if the user entered the wrong command name or alias then return: invalid command/alias". However, when implementing this logic, ...

Can someone guide me on how to utilize the C# driver to query MongoDB with a query in string form?

When working with MongoDB, I often find myself in need of running a standard query. For instance: {"$and":[{"Name":"Accelero JKT M Tun XL "}]} Normally, I create queries using the Query object in C# and execute them like this: MongoCollection<BsonDoc ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...

Experiencing Sluggish Performance with Web Scraping Using Selenium?

When using selenium to extract data from a webpage, I'm encountering a slowdown issue over time. It reaches a point where it fails to complete the list of people and times out. I understand that the process naturally slows down as I maintain a HashSe ...

Conditional statement that includes Node.js scheduling function

I am currently working on a Node.js project and I need to execute a specific portion of conditional code after waiting for five minutes since the last piece of code executed. This action should only happen once, not on a daily basis or any other frequency. ...

How can the CORS issue be resolved when sending a form from a client to an AWS API gateway function?

Within my front end React application, I am looking to implement a contact form that will submit data to a Lambda function via an API Gateway with a custom domain attached. The frontend operates on the domain dev.example.com:3000, while the API Gateway is ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

What could be causing my code to become unresponsive when using a for loop compared to a loop with a specific

After spending a solid 4 hours on it, I finally managed to figure it out. There were no errors popping up, so I resorted to using the debug feature which unfortunately didn't provide much insight. Without any error messages to guide me, I wasn't ...

Sending the image's identification number as a parameter to a function and showing the total number

On a static page, I have the following HTML markup: <div class="middle-content"> <div class="white-div"> <div class="like-buttons"> <img id="1" src="up.png" onclick="onClick(true, this.id)" /> &l ...

Can we find a different way to address this issue with a "functional programming" mindset that doesn't involve utilizing the `forEach` method?

There has been a discussion about whether or not we still need to use forEach in JavaScript due to the availability of new language features. Some have suggested that this shift is an indirect push towards functional programming. I recently came across an ...

Having trouble grasping the problem with the connection

While I have worked with this type of binding (using knockout.js) in the past without any issues, a new problem has come up today. Specifically: I have a complex view model that consists of "parts" based on a certain process parameter. Although the entire ...

ES6 Class Directive for Angular 1.4

I am currently exploring the possibility of incorporating a directive from version 1.4 and adapting it to resemble a 1.5 component. By utilizing bindToController and controllerAs, I aim to integrate the controller within my directive rather than using a se ...

Steps for implementing a JavaScript script to modify all values within a table

I am facing an issue where I need certain "td" elements to disappear when the date associated with them has passed. However, currently only the first column is affected while others remain untouched. <script type="text/javascript"> //<![CDAT ...

Save the raw InputMask data in Formik with Material-UI

I currently have Input Mask implemented with a customized Material UI text field inside a Formik form: <InputMask mask="999-99-9999" maskChar="X" value={values.ssn} ...

Guide on building a "like" button using a Node.js Express application

I am in the process of developing a website using node, express, and mongodb. I am facing an issue with passing a variable value from my ejs file to the server side. Can someone help me solve this problem? Here is what I have attempted so far: Example Ht ...