Protractor/Js - Facing difficulty in retrieving precise data on table row and column counts

I am attempting to confirm the number of rows and columns in a table by using Protractor/Js.

After testing four different functions, I have received inaccurate results. My suspicion is that my locator, which is '.tsc_table_s13', may be incorrect.

For Rows:

 $(locator).all(by.xpath('.//tbody/tr')).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

Alternatively...

var table = element.all(by.css(locator));
        table.all(by.tagName("tr")).count().then(function (data) {
            expect(data).to.equal(parseInt(mycount));
        });

For Columns:

$(locator).all(by.xpath('.//tbody/tr/td')).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

Alternatively...

var table = element.all(by.css(locator));
        table.all(by.tagName("td")).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

When checking the column count, I receive 25 (or 26) when I should only have 6. The row count shows 0 instead of the expected 4. You can view the table here -

Answer №1

Below is a straightforward solution //test.spec.js

 describe('examining all rows and columns', function() {
   var rowCount;
   var colCount;
beforeEach(function() {
  browser.waitForAngularEnabled(false);
  browser.get('http://www.toolsqa.com/automation-practice-table/');

  rowCount = element.all(by.xpath('.//tbody/tr'));
  colCount = element.all(by.xpath('.//tbody/tr[1]/td'));
}); 

it('should display the counts of rows and columns', function() {
  //expect(rowCount.count()).toEqual(4);
  //expect(colCount.count()).toEqual(6);
  rowCount.count().then(function(count) {
  console.log(count);
  })
  colCount.count().then(function(count) {
  console.log(count);       
   })
  });
 });

Answer №2

The count returned is accurate, as confirmed by manually testing the locator in Chrome which yields the same result.

Initially, the result is obtained from the locator .tsc_table_s13 and then a new locator is concatenated on top of it.

Here are the attached results: https://i.sstatic.net/aCGBW.png https://i.sstatic.net/lzodx.png

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

Harnessing the power of Div tags with a href attribute as placeholders for interactive menu items

I am facing an issue with multiple divs covering different portions of a menu on a background image of a webpage. Each div contains an anchor tag linking to another page and playing a click sound upon clicking. To ensure the cursor changes across the ent ...

Infinite error loop during start-up in AngularJS application due to digest cycle overflow

Just starting out with Angular and working on a new project using node, jade, and angular. I'm having trouble implementing a catch-all server route. Every time the index page loads, it gets stuck in a loop and crashes the app. I've tried several ...

Angular 5 allows users to easily add products to their cart by specifying the quantity, while also displaying the total

In my Angular 5 application, I have implemented a feature where users can select the quantity of products and the total price is calculated based on the selected quantity. However, there is a limit on the quantity that can be added for each product. For ex ...

When a link is added, the Bootstrap drop-down button may become unresponsive

I've encountered an issue with a Bootstrap dropdown menu that I created using jQuery and Bootstrap. The links within the dropdown menu are not redirecting to the correct pages as intended. Can someone help me identify what mistake I might be making he ...

npm command syntax to accept multiple arguments

Struggling to pass arguments in an npm command and utilize them in my script For instance: npm run test -b chrome -e QA "scripts": { "test": "something.js ./xyz/abc/cdf --something \"{\\\"browser\\\": \&bsol ...

Starting jQuery on embedded websites

I developed a platform that relies on JavaScript. Users of my platform are required to paste a code similar to Google Analytics, which automatically deploys a custom set of JavaScript functions along with the latest jQuery 1.9 through Google. The issue I ...

Updating language settings on-the-fly in a Vue application does not automatically refresh the translated content displayed on the website

My Vue app is quite large, built with Vuetify, and I recently integrated vue-i18n into it. The json translation files are set up correctly, and the $t() calls work fine in my components and other .js files. However, I'm struggling to change the locale ...

When working with multiple states in React, the toggle does not update on click when using setState

As a beginner in React JS, I have been learning and experimenting with state management. Initially, I successfully used setState to change the state. However, I encountered an issue when attempting to work with multiple states simultaneously – it didn&ap ...

Display a modal window when a dropdown list is selected

I am working on an ASP .NET MVC application where users need to be able to add content to a page. This content could include things like locations, photos, and more. I have implemented a dropdown list in my View that contains all the different content opti ...

Choosing the attribute value using jQuery/CSS

Looking for a way to retrieve attribute value using jQuery/CSS <dt onclick="GomageNavigation.navigationOpenFilter('price-left');"> I tried using $("dt[onclick='GomageNavigation.navigationOpenFilter('price-left')']") bu ...

How can I access the data variables from a JSON request within a function?

My task involves loading multiple JSON files from an array called bunchOfData, with each file having a corresponding URL. How can I access my variable "myI" within the processData function? for(var i = 0; i < bunchOfData.length; i++){ $.getJS ...

Error Panel Style Message Format:

Currently, I am utilizing PrimeFaces, which utilizes JQuery UI not just for its functionality but also for its CSS styling framework. The issue I am facing stems from my lack of understanding about the CSS framework, as I have been unable to locate any exa ...

Laravel: Input information into a form containing multiple dropdown menus

I am in search of a Laravel or HTML example that demonstrates filling out a form with multiple drop-down lists. Here's my scenario: I have the following text inputs: name_customer, phone_customer, email_customer. I want the form fields to automatical ...

Issue with implementing MUI Style Tag in conjunction with styled-components and Typescript

I have created a custom SelectType component using Styled Components, which looks like this: import Select from '@mui/material/Select'; export const SelectType = styled(Select)` width:100%; border:2px solid #eaeaef; border-radius:8px ...

Encountering a ReferenceError message that says "readFile is not defined

Currently, I am in the process of learning Node.js and encountering an issue. When I type 'node .' in the terminal, I receive a ReferenceError: readFile is not defined message. Below is the code snippet: const express = require("express"); co ...

Creating concentric circles with text inside is a fun way to add depth and creativity to

Seeking assistance in creating an identical design using HTML and CSS. Any help will be appreciated, thank you in advance. Click here to view the image ...

Trigger in Firebase returns a different node key when making an update request

Examining my database structure, I am aiming to create a Firebase trigger that will update the RoundScore for a specific PlayerID whenever any section of the '/SCORES' node is modified. "SCORES" : { "2017" : { "Round_1" : { ...

Maximizing JavaScript efficiency: Returning a value within an if statement in an AJAX call

In my function, I have a condition that checks the idType. If it is 1, an ajax call is made to a php file to retrieve the name associated with the specific idName and return it. Otherwise, another example value is returned. function obtainName(idName, idTy ...

What allows me to modify the border color and thickness of my table's <thead>, but prohibits me from changing the background color?

I have successfully changed the border styling of the top bar in the table, however, I am struggling to change the background color no matter what I try. Can someone point out where I might be making a mistake? Here is my code: <table> <thead> ...

In cases where a selection is not made from the dropdown menu, the textbox should be enabled to input data into a MySQL table through the

Hello, I am currently working on a triple dropdown for selecting country, state, and city using AJAX. Here is the reference link: . It is working successfully, but I would like to implement a feature where if a state has no cities in the database table, a ...