Acquire the ng-model within an ng-repeat using Protractor

How do I access the ng-model within ng-repeat using protractor?

<div ng-repeat="field in master.linker | orderBy:'country.name'">
    <div>
        <p> {{ field.country_name }} </p>
        <input ng-model="field.text">
    </div>
</div>

I have tried this code, but it has not been successful :

var result = element.all(by.repeater('field in master.linker').column('field.text'));

result.forEach(function(entry) {
    console.log(entry);
});

My goal is to compare values:

result.forEach(function(entry) {
    if (entry.country_name === 'en') {       
        expect(entry.text (from ng-repeat)).to.eventually.equal(value)
    }
});

Answer №1

The .column() method is specifically designed for working with bindings, not models.

In this scenario, it is recommended to utilize the by.model() locator:

var result = element.all(by.repeater('field in master.linker'));

result.each(function(entry) {
    var input = entry.element(by.model("field.text"));

    // perform actions on the input
});

To retrieve input values, you can use map():

var inputValues = result.map(function(entry) {
    return entry.element(by.model("field.text")).getAttribute("value");
});

// display input values
inputValues.then(function (values) {
    console.log(values);
});

Addressing a supplementary query from a comment:

If I have an array containing only specific fields from my ng-repeat, how can I compare using "if (field.country_name === "en") { expect(field.text).to.eventually.equal(value)}" ?

You can achieve this by employing filter():

var fields = element.all(by.repeater('field in master.linker'));
fields.filter(function (field) {
    return field.element(by.binding("field.country_name")).getText().then(function (country) {
        return country === "en";
    });
}).then(function (filteredFields) {
     var input = filteredFields[0].element(by.model("field.text"));
     expect(input.getAttribute("value")).to.eventually.equal(value);
});;

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

"ng2-file-uploader necessitates a browser refresh in order to function

I am currently utilizing ng2-file-upload within my Angular 10 project to allow users to upload their photos. The upload process is functioning correctly, but the issue arises when the newly uploaded photo does not automatically appear in the photo list wit ...

Struggling to implement a Datepicker in the date column of a table created using HTML and JavaScript

I am encountering an issue while creating a table in html and javascript. I am unable to use a Datepicker in the date column when inserting a new row, even though it works fine when using in normal html code. Below is the javascript function: //Script fo ...

Exploring the depths of Node.js and intrigued by its scope

Currently, I'm engrossed in an ebook titled "The Node Beginner Book." It essentially consists of one extensive exercise spanning around 50 pages, covering a wide range of basics. Lately, I've been immersed in Python and have a background in PHP. ...

Challenges with AngularJS performance when using ng-model compared to ng-class and other directives

Within my Angular application, I have a list that utilizes ng-repeat along with a button that toggles the checked property in all items (version 1.4): <button ng-click="selectAll()">select all</button> Here is an example of how it works: < ...

Ways to determine if a web browser is executing javascript code (without altering the javascript on the webpage)

Working on creating a custom PHP client for Selenium, I've encountered an issue with implementing the waitForPageToLoad() function: The problem lies in just checking the document.readyState, as there could be JavaScript scripts running on the page (l ...

assign a role to a discord.js user using the role stored in the client class variable

Is there a way to dynamically assign a role to a user using the client variable const client = new Client({ intents: [GatewayIntentBits.Guilds] }); instead of through an interaction? The user's role needs to be updated when a 3rd party request is rec ...

Is there a way to catch a downloaded file inside an iframe?

My dilemma involves an external site embedded in an iframe that contains a save button to download a json file. I am seeking a solution to capture the contents of this downloaded file within my own code. Is there a possible method for achieving this? Rese ...

Guide to incorporating JavaScript libraries from NPM into a child theme built on Understrap

I am looking to incorporate the Chart Js library within my custom Understrap Child Theme. Instead of simply using a CDN script, which could potentially slow down load times or cause errors if the CDN is not accessible, I have opted to import it into my pac ...

AngularJS offers a helpful solution for exchanging data across controllers by utilizing the $broadcast method

I've been struggling with utilizing $broadcast and $on functions to transfer data between two controllers. On my main webpage, there is a button that increments a variable by 4 each time it's clicked: <!DOCTYPE html> <html xmlns="http: ...

Unresolved CORS Issue in Vue.js Using Axios with undefined Proxy Response

My attempt to retrieve data using a client vueJS on port 8080 from the REST API on port 3000 is resulting in a CORSE Error. Interestingly, a successful POST operation occurs without any issues. To resolve this error, I followed the instructions provided in ...

Can Mongoose be used to merge select() and sample() functions together?

When working with Mongoose, you have the option to retrieve documents with specific fields and limit the results to only 10. This will consistently return the same set of 10 documents each time. products = await Product.find({ category: category, }) ...

Utilizing various lodash filters in React for enhanced data manipulation

In my code, there is a function that filters a large set of objects based on specified inputs. The code snippet for this filtering function looks like this: filterLocations(filters) { let filteredLocations = _.filter( this.state.locations, locat ...

What is preventing me from choosing the particular Game object?

I am looking to enhance my gaming experience, but I am encountering an issue with my selection process that is causing an exception to be thrown. My desired SQL query is as follows: Select * from Games where userId = 3 order by createdAt desc gameControl ...

There was an issue with parsing the json data using the JSON.parse() function

Utilizing the json_script template tag in Django, I am obtaining a JSON from a context view. The JSON is received as follows: {{rules|json_script:"rules"}} <script lang="javascript"> const rules = JSON.parse($('#rules').text()) </ ...

The issue of receiving a 500 error when making a POST request in node.js

I have created my own unique REST API that utilizes an NLP API internally. I need to post data on their URL, but unfortunately I am encountering an error that is causing my API to return a 500 error to the frontend. Below is a snippet of my server.js code ...

jQuery is consistently lagging one step behind when calculating the sum with keypress

I am currently working on developing a calculator that adds up the values entered with each key press. Here is the code snippet I have been using: $('#padd').keypress(function() { var ypoints = "200"; var points = parseInt( $(th ...

The lineTo() function does not support passing in an array as its argument

My goal is to draw lines based on the coordinates provided in the array called points. However, I encountered an error when calling the method. Oddly enough, when I try to access a specific element using console.log(points[1][1]), it works perfectly. Can s ...

Efficiently verifying elements within an array

I have a roster of students categorized based on their activity status - some are active, while others are inactive. var allActive = [{id: 1, active: true}, {id: 2, active: true}, , {id: 3, active: true}]; var someNot = [{id: 4, active: true}, {id: 5, act ...

Is there a way to allow an HTML page rendered by node.js to communicate back to its corresponding node.js file?

I am currently in the process of developing a registry system using node.js and HTML. However, I have encountered an issue where my HTML page is rendered by node.js, but when trying to call it back to the node.js file, it appears that the JS file cannot be ...

An Illustrative Example of Inheritance in Javascript?

I've been searching on various platforms for a straightforward example of inheritance without much luck. The examples I've come across are either too complex, obscure, or just not user-friendly. I have multiple service functions that all share so ...