Struggling to access content with Protractor Promise callbacks. What is the best approach for invoking methods on the returned item?

Upon hitting the debugger in the code snippet below, the value of 'thing/item' shows as empty (refer to the image).

it('CheckAllLinks:', function () {
    browser.ignoreSynchronization = true;
    browser
        .findElements(by.tagName('a'))
        .then(function (items) {
           items.forEach(function (item) {
              var thing = item;
              debugger;
        });
    });
 });

For instance, when using the immediate window in Visual Studio, any call to these methods only results in three dots (...).

Although I acknowledge that this is a promise, I am unsure of how to utilize any of the methods to validate content and click the link as well...

Answer №1

It has been discovered that the essence of these calls themselves lies in the concept of promises. Promises are only fulfilled when the .then statement is triggered. In the example below, two things are being promised: the text and the href of each link.

it('CheckAllLinks:', function () {
    browser.ignoreSynchronization = true;
    browser
        .findElements(by.tagName('a'))
        .then(function (items) {
        items.forEach(function (item, i) {
            var test = item.getText().then(function (text) {
                item.getAttribute('href').then(function (href) {
                    debugger;
                });
            });
        });
    });
});

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

Filtering data on objects in Angular can be achieved by utilizing the built-in

Retrieving data from the backend using this function: private fetchData(): void { this.dataService.fetchData().pipe( tap((response: any) => { this.persons = response.results; this.familyMembersTrue = this.persons.filter(x =&g ...

The image tag fails to appear on the browser when the client attempts to access it

Greetings, I am new to web development. I am attempting to create a simple static website that only displays an image in the header tag of an HTML file. The server seems to be working correctly in sending responses to the client, but the problem lies in t ...

What is the best way to prioritize loading JSON models first in three.js and declare a variable before initializing?

I am looking to efficiently load multiple JSON models and store them in global variables for easy access. This will streamline tasks like copying, translating, and more without the need to reload a model each time. After trying various methods, I have not ...

Leverage Redis to facilitate memory sharing among node.js instances in RxJS

We are currently developing a project that involves creating an event processor using RxJS. The system relies on specific rules where input is collected from various sources and output is generated based on the frequency of inputs exceeding a certain thres ...

exploring the capabilities of sockets in PHP, reminiscent of the functionality found in Node.js

I recently downloaded and tried out a basic chat app with Node.js: https://github.com/socketio/chat-example The app is functioning properly. The server-side code is quite straightforward: var app = require('express')(); var http = require(&ap ...

Looking to duplicate the elements with the click of a button?

I am in need of assistance with my registration form. My goal is to move the elements contained within the <fieldset> tags to the end of a row when the user clicks the + button. The result you see initially has been recreated. Thank you for your s ...

My code gets disrupted when I switch between ids and classes

I'm currently learning about javascript and jquery, attempting to implement various scripts. I successfully executed the following script: jQuery(document).ready(function($) { var scroll_start = 0; var startchange = $('#homepage-header' ...

``Is it possible to adjust the style of an HTML element based on the style of another element?

Within my web application, I am dynamically changing the style of an HTML element using JavaScript. Below is the code snippet: function layout() { if(document.getElementById('sh1').getAttribute('src') == "abc.png") { docum ...

Mongoose is unable to update arrays, so it will simply create a new array

Having trouble updating my collection without any errors. Can someone lend a hand? I've been at this for 3 hours now. const product_id = req.body.cartItems.product_id; const item = cart.cartItems.find(c => c.product_id == product_id); i ...

What is the best way to link a socket.id with an element in an array?

I am currently working on creating a chat-room where the names of connected users are shown in an 'Online Users' section. The following code snippet adds each user's name to an array and displays the contents of that array. However, if a u ...

Verifying a form submission using a personalized model popup

I have several delete forms in my application that I want to confirm using javascript/jQuery before proceeding. An easy way to do this is: $('form.confirm-form').submit(function(){ return confirm('Are you sure?'); }); This method ...

Neglecting to refresh the content within the modal body

I am facing an issue with an empty modal on my webpage and an AJAX call that I am trying to execute as shown below (simplified for easier understanding). function fetchContent(x) { $.ajax({ type:"POST", url:"link", data:{id:"123"}, suc ...

Currently in the process of modernizing an outdated method to a more up-to-date version in Jasmine, encountering issues related to

Currently working to update the method throwOnExpectationFailure to the newer one oneFailurePerSpec. According to the Jasmine documentation, this can be achieved by: Use the `oneFailurePerSpec` option with Env#configure After conducting research, I came ...

Upon attempting to RUN microdnf install google-chrome-stable, it returns the error message 'verification failed as the repository for google-chrome is GPG enabled.'

I'm facing an issue with my Dockerfile setup. It used to work perfectly fine, but now I am encountering the following error: #8 48.09 Downloading packages... #8 91.38 error: package google-chrome-stable-116.0.5845.96-1.x86_64 cannot be verified and re ...

Is it sufficient to only capture 4xx errors?

Is it necessary to catch both 4xx and 5xx errors, or is catching just 4xx errors sufficient? In regular testing of my code, when would a 5xx error even occur? ...

Error encountered: Attempting to access the 'length' property of an undefined variable in JSON data while using the $.each function

When I execute the following code snippet: var obj = $.parseJSON(json.responseText); $.each(obj.collection.response, function (i) { $.each(this.PRESENT_STUDENT, function (i, j) { $.each(j , function (i, j){ $( ...

Developing a custom edit template with Infragistics through coding

Currently, our team utilizes the Infragistics grid without binding datasets until runtime. Instead, we set up the grid settings in code as per the preference of our senior developer. While effective, this method can seem a bit lengthy. I am interested in ...

Textures in Three.js are appearing black when loaded

Currently in the process of transferring a mesh from Maya to three.js. After converting the Maya file to .obj format and loading it onto the page, I noticed that Materials with image textures (1024x1024 .tga files) appear black, while Materials with solid ...

The duration from when the Ajax request is sent to when the response is received results in

Has anyone experienced strange results when measuring the time between sending and receiving an ajax request? Sometimes I get negative values. Can someone shed light on this peculiar behavior? var before = 0; var after = 0; $.ajax({ url: 'data.ph ...

Arrange two arrays by organizing them based on the contents of one in JavaScript

Consider the following two arrays: priceArray= [1, 5, 3, 7] userIdArray=[11, 52, 41, 5] The goal is to sort the priceArray in such a way that the userIdArray also gets sorted accordingly. The desired output should look like this: priceArray= [1, 3, 5, ...