Retrieving the count of elements through the function `element.all(by.id())`

I am trying to achieve the following:

it('should retrieve the number of API Keys from a list'), () => {
    let numApiKeys = 0;
    element.all(by.id('ApiKeyList')).count().then(function(count) {
        numApiKeys = count;    // assuming count = 5
    });
    console.log(numApiKeys);   // however, it displays numApiKeys = 0
});

I am struggling to obtain the length of 'ApiKeyList'; numApiKeys consistently returns 0.

Is there a way for me to accurately determine the length of the list?

Answer №1

Here is a helpful suggestion for you:

    const itemCount = await element.all(by.id('radioApiKeyList')).count();
    console.log(itemCount);

Answer №2

According to Joaquin Casco, the code below was successful:

it('should retrieve the number of API Key list'), async () => {
    // assuming ApiKeyList has a length of 5
    let numApiKeys = await element.all(by.id('ApiKeyList')).count();
    console.log('numApiKeys = ' + numApiKeys);   // numApiKeys = 5 
});

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

Show the subscription response data in Angular

When utilizing the code snippets below from two different components, I am able to receive a valid response value from the subscriber. dataService.ts fetchFormData(){ return this.http.get('http://localhost:48116/RecuruitmentService.asmx/addRoleTest ...

The module 'node:fs' could not be located. Stack required:

I've been developing a Teams app with my tab in React and TypeScript. (In case you're unfamiliar, the tab can be seen as an individual React app) Currently, I'm setting up linting using ESLint and Prettier. I have successfully run the scri ...

Utilize a universal type for the property name in TypeScript

In my code, I am using an enum as a propName for an object-like type. export enum WeaponClass { smallLaser = "smallLaser", } export type WeaponType = { [propName in WeaponClass]: number }; const weapons: WeaponType = { [WeaponClass.smallLase ...

The selected value of the PrimeNG p-checkbox cannot be determined using a function when binding to [ngModel]

These are the rows of my custom p-table <tr> <td>{{user.userName}}</td> <td>{{use.userSurname}}</td> <td *ngFor="let group of groups"><p-checkbox [(ngModel)]="showVal ...

Issues surrounding the presentation of error validation messages

I need assistance with validating a registration form. The form includes fields for email, password, and confirm-password. To validate the email, I use a pattern for correctness, while for the password I require one uppercase letter, one lowercase letter, ...

Encountering an error stating "Potential null object" while attempting to retrieve the total count of characters and numbers in a given string

Currently, I am trying to find the number of characters and digits that repeat more than once in a given input string. For example, if the input is "zzrrcde", the output should be 2 as both z and r occur more than once. Here is the function I have writte ...

Tips on retrieving a value nested within 3 layers in Angular

In my Angular application, I have three components - A, B, and C. Component A serves as the main component, Component B is a smaller section nested inside A, and Component C represents a modal dialog. The template code for Component A looks something like ...

Angular country selection dropdown featuring national flags

Can anyone help me find an Angular Bootstrap dropdown list of countries with flag icons and country codes? For example: United Kingdom - UK Please take a look at this reference image: https://i.sstatic.net/UEfvW.png I want the dropdown to resemble the o ...

Zoom-to-fit functionality in Three.js with spacing adjustment

I am currently working on developing a zoom-to-fit function that can accurately adjust a list of points to fit within a specified drawing area, while also allowing for customizable offsets on all sides of the image. In essence, I aim to zoom-to-fit within ...

I noticed the Navbar toggler is visible, but when I try to click on it, the navbar items do not appear

Can anyone help with an issue I'm having with my navbar? It has two items (a ngbdropdown and a link), but when I reduce the resolution, the toggler appears. However, when I click on it, nothing happens. Here is the html code I have so far: (Note that ...

Mistakes encountered following the installation of lodash in Angular 2

After adding lodash to my Angular 2 project, I encountered a significant number of errors. To troubleshoot, I created a new project using the CLI: ng new tester, then I added lodash with npm install --save @types/lodash. When I ran ng serve, I received the ...

tips for deleting an element from an object in angular

I'm dealing with an object that looks like this: { first_name: "acasc" last_name: "acsac" email: "acac" mobile_number: "acac" password: "acac" confirm_password: "acac" } Here's what I need to do: If the password a ...

Choose a specific div element from a collection of dynamically generated divs in Angular

I have been working on a code to dynamically generate div elements using the *ngFor directive. Here is what I have so far: <div *ngFor = "let item of Items"> <p>Item : {{item}} </p> </div> The challenge I encountered is that w ...

Error: Unable to inject null value into injector chain [c -> n -> J -> J -> J]

As I delve into an older angular project that was created by a former colleague, I am faced with the task of debugging it. However, as I run the application, I encounter the following error message: NullInjectorError: R3InjectorError(n)[c -> n -> J - ...

Exploring Function Overriding in TypeScript

Currently, I'm working on developing a TypeScript method. import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; @Injectable({ p ...

Trouble with locating newly created folder in package.json script on Windows 10

I am facing an issue in my Angular application where I am trying to generate a dist folder with scripts inside it, while keeping index.html in the root folder. I have tried using some flag options to achieve this but seem to be stuck. I attempted to automa ...

Creating a generic class in Typescript that can only accept two specific types is a powerful

When designing a generic class, I am faced with the requirement that a property type must be either a string or number to serve as an index. If attempting something like the code snippet below, the following error will be triggered: TS2536: Type 'T ...

Troubleshooting Problems with Tsconfig and Output Directory

I'm experiencing an issue with the outDir setting in my tsconfig.json file. Here is what my tsconfig file looks like: { "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, ...

I'm facing an issue where Typescript isn't recognizing Jest types

The Challenge Setting up a TypeScript project with Jest has been proving difficult for me. It seems that TypeScript is not recognizing the Jest types from @types/jest, resulting in an error message like this: Cannot find name 'test'. Do you nee ...

How can I display data saved from step 2 in a multi-step form with 4 steps, when I return from step 3 to step 2?

Let's consider this scenario: Imagine the user is at step 2 and types their name into <input type="text" class="form-control input-xl" ngModel name="firstName"> They proceed to step 3 but then decide to return to step 2. The information entere ...