Searching for a way to obtain the iterator index/key in protractor along with angular?

Is there a method to retrieve the iterator index/key while searching for elements by repeater?

protractor.By.repeater("(id,cat) in pets")

In this particular scenario, I am aiming to acquire the "id" of the cat. The "id" is not displayed as one of the columns in the table, rather it is utilized for navigation through ng-click="goto('/pets/'+cat.id)". There is no binding within the HTML like {{id}} or {{cat.id}}, so when attempting the following:

ptor.findElements(protractor.By.repeater("(id,cat) in pets").column('cat.id'))

it results in an empty element: []

I have also attempted, without success, something along the lines of:

ptor.findElement(protractor.By.repeater("(id,cat) in pets").row(0).column('cat.id'))

What is the appropriate way to access that specific index?

Here is the answer provided by Jmr in non-condensed syntax:

ptor.findElements(protractor.By.repeater('(id, cat) in pets')).then(function (arr) {
    arr[0].evaluate('cat.id').then(function (id) {
        console.log(id);
    }); 
});

Answer №1

If you need to assess a value that is not visible on the page, using the 'row' and 'column' methods won't be effective. By utilizing the repeater function, you can generate an array containing all the rows. Subsequently, you can employ the evaluate command to evaluate Angular expressions within the element's context. Below is an example of how this can be done (with abbreviated syntax):

element.all(by.repeater('(id, cat) in pets')).then(function(arr) {
  arr[0].evaluate('cat.id'); // This promise resolves to the id.
});

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

Logging out of Google when refreshing the page

I am currently working with the setup outlined below: .service('googleService', ['$q', function ($q) { var self = this; this.load = function(){ var deferred = $q.defer(); gapi.load('auth2', function() ...

Locate every item that has a value that is not defined

My data is stored in indexeddb, with an index on a text property of the objects. I am trying to retrieve all objects where this property's value is undefined. I have been experimenting with IDBKeyRange.only(key), but when I use null, undefined, or an ...

Verify if the expression can be found in the DIV element's style

Recently, I encountered a situation where a DIV contains a background image that is either set directly or generated as an SVG. I needed to figure out how to determine when the DIV contains the SVG-string. Here are my two DIVs: <div class="cover m ...

"Inserting" a fresh key-value pair into a JavaScript Object

I know that with arrays, only array elements can be added using the .push() method. My goal is to achieve a similar functionality for objects. I am familiar with both dot and bracket notation, so this is not a basic question for me. However, I need to do ...

Tips for setting up a scheduled event on your Discord server using Node.js

Hello fellow programmers! Recently, I've been working on a Discord bot using discordjs sdk. I'm trying to implement a feature where the bot creates an event every week. I went through the discordjs guide and checked the discord api documentati ...

Distinguishing between native and custom error objects: a comprehensive guide

When working with errors in my node app, I find it challenging to handle both custom and native errors seamlessly. Errors are not just ordinary JavaScript objects, which adds complexity to error handling. To manage custom errors, I am experimenting with t ...

Discovering duplicate values in a JSON object using JavaScript (JQuery)

Below is a JSON object that contains information about various materials: [ { "idMaterial": "Alloy 450 (15Cr6Ni1.5Cu)_S45000", "tipoMaterial": "Alloy 450 (15Cr6Ni1.5Cu)", "uns": "S45000", "temperatura": "NL", "p ...

Displaying a list of JSON data in HTML using Angular.js is a breeze

I am attempting to create an HTML list displaying the id fields of game objects from a json file. However, it is not appearing in my user interface. I am unsure why it is not rendering properly. ---core.js--- var gameapp = angular.module('gameapp&ap ...

jQuery does not allow for text input values to be posted

Having an issue with a form using the POST method. I have some PHP controls that are being calculated in jQuery. While all the form control values are accessible in the next form using POST, the values added through jQuery are not posting to the next form. ...

Unusual manifestation of the Array

I defined a list array as: list: string[] = []; and added elements to it like this: let infoFile: string = fileReader.result; this.list.push(infoFile); After checking the console log, I noticed something strange [] 0 : "data:image/jpeg;base ...

Click event doesn't trigger the 'else if' statement in jQuery

Having trouble with a button click issue. In the following code, when the button is clicked, it checks if the text on the button is "day". If so, it changes the background-color of the body to red and updates the button text to "night". I am struggling wit ...

Adding a class-matched element with a corresponding ID

Despite finding similar questions, I am still unable to achieve the desired outcome. Here is a list: <ul> <li class="class1"></li> <li class="class2"></li> <li class="class3"></li> <li class="class4"&g ...

Modifying the input value within the "input" event handler stops the firing of the "change" event in Chrome and IE, although this does not occur in Firefox

Within this code snippet, I have an "input" event handler that updates the input value as the user types. Additionally, there is a "change" event handler to monitor any modifications made to this field. However, there seems to be an issue where the "change ...

Retrieve the output of a JavaScript function and submit it as extra form data

I am working on a JavaScript function that looks like this: <script type="text/javascript"> function doSomething() { var s = 'some data' return s; } </script> and @using (Html.BeginForm(new { data_to_send = ...

The canvas could not be loaded properly in THREE.Texture()

I'm having trouble with adding an image onto the side of a cube that I'm creating. The image loads onto the canvas, but I'm struggling to incorporate it into the texture. function createPictureCanvas(text, font, foreground, background, xres ...

Trigger an endless loop upon window.onload event

Every now and then, when a user opens the page, it starts flickering and resizing itself. After checking the log, it appears that the submit function is being called multiple times, but I can't reproduce this issue in my own environment. Is there som ...

Discovering a full class entity within an array using Javascript

I am currently working with an array of objects that serves as the datasource for a materials table. Before adding a new row, I need to ensure that it does not already exist in the array. Since there is no key value assigned to the objects in the array, I ...

Alter Express routes automatically upon updating the CMS

Currently, I am working on a project that utilizes NextJS with Express for server-side routing. lib/routes/getPages const routes = require('next-routes')(); const getEntries = require('../helpers/getEntries'); module.exports = async ...

Issues with Angularjs $http.get functionality

On the server side of my ASP.net MVC application, I have a method that looks like this: [HttpGet] public JsonResult GetTrenings(string treningId) { var tempId = Guid.Parse(treningId); var trening = TreningService.GetTreningById ...

Steps for generating a unique division element for every javascript response

How can I dynamically create a new div for each response in JavaScript? The message is in JSON format containing all the messages sent and received. This is my JavaScript code: $.get("MessageServlet", function (responseJson) { $.each(responseJ ...