Protractor obtainElementProperty awaiting - fulfilling result

We are encountering an issue where we are trying to store a value from the getAttribute function in a local variable, but resolving the promise seems to be problematic for us.

return element(by.id('foo')).getAttribute('value');

This code snippet above returns a promise when executed, and our attempt to store the value using async/await also results in another promise object being returned:

let result = await element(by.id('foo')).getAttribute('value');

We even tried chaining promises to resolve it as shown below:

static async  getStreetNumberAsync() {
       this.getStreetNumber().then(function(value) {
            return new Promise.resolve(value);
       });
   }

However, waiting for the promise to be resolved did not yield any success. We are seeking guidance on what we might be doing incorrectly and how best to handle this situation.

The complete code excerpt is provided here:

static getStreetNumber(){
       return this.MPP().txtStreetNumber.getAttribute('value');
}

static async  getStreetNumberAsync() {
       let value = await this.getStreetNumber();
       return value;
}

static editMyProfile(){
       let value = this.getStreetNumberAsync();
}

In the end, the value stored in 'value' appears to be of type promise [object promise]. Any insights or assistance would be greatly appreciated!

Thank you in advance!

Answer №1

Utilize the existing async function you have at your disposal:

static async findStreetNumber() {
  let data = await this.getStreetNumber();
  return data;
}

If a Promise is more suitable for your needs:

return new Promise(resolve => resolve(data));

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

The results from the loop are being outputted outside of the <table> using $.each

Currently, I am making an Ajax call to fetch a large number of results from the database. I am then using jQuery to loop through these results and create a simple table. However, I am facing a problem where the loop is placing the results outside of the &l ...

Can you help me figure out what is causing an issue in my code? Any tips on removing a collection from MongoDB

I'm currently facing an issue with deleting a collection from MongoDB using the Postman API. The update function in my code is working perfectly fine, but for some reason, the delete function is not working as expected. It keeps displaying an internal ...

Transforming all numbers to a consistent scale with the help of Numeral JS

Is there a way to customize the output of the numeral.js function so that it always returns numbers in thousands? For example, converting 1000000 to 1000k and 100 to 0.1k. console.log( numeral(1000000).format('0a') ); <script src="https ...

Row within a table displaying link-like behavior

Here is the code I'm currently using: $('.table-striped tr').click( function() { var link = $(this).find('a').attr('href'); if(link != 'undefined') { window.location = link; } }).hover( func ...

BufferGeometry lines in THREE.js are failing to render when their starting point is outside the view of the camera

Currently, I am in the process of developing a trace-line function for a visualization project that involves transitioning between different time step values. However, I have encountered an issue while using THREE.js's BufferGeometry and the setDrawRa ...

How to retrieve an element by its class using JavaScript and Jquery while implementing a

I am working on creating a quiz example using Jquery, but I am facing some challenges when trying to manipulate CSS classes with hover in Jquery. .right{ background-color: white; } .wrong { background-color: white; } .right:hover { background-color ...

Download and print the embedded PDF file

I am having trouble figuring out how to add 2 external buttons to print and save an embedded pdf on my webpage. Despite searching Google for hours, I have not been able to find a solution that works. The embedded object already has buttons for printing and ...

The horizontal axis displays the hours from 12:00 to 12:55 instead of specific calendar dates

This script creates a highchart that includes 2 Y axes and 1 X axis: $('#main_chart').highcharts({ chart: { zoomType: 'xy' }, title: { text: 'Overview' }, xAxis: [{ ...

How can I access the attributes of items stored in an array in JavaScript?

Input was being retrieved from an HTML text box and stored in an object with multiple properties. Two functions, addAddress and displayAddressDetails, were created for adding data and displaying it. However, there seems to be an issue with displaying the d ...

Optimal approach for implementing custom method into Array (native object)

I recently developed a node module that includes specialized methods for manipulating arrays and strings. Initially, I utilized the module as usual by requiring it in my code: Option 1. const invSlice = require('inverted-slice'); let arr1 = [1 ...

Exploring ways to find a particular value within an array of objects

Struggling to make my code render the data upon searching for a specific value. I attempted using a for loop, but I keep encountering an 'unexpected token' error. Is there a more effective way to accomplish this task? While this may seem like a s ...

Performance comparison between Javascript Object and Map/Set for key lookup

I decided to experiment with the performance of JavaScript Object, Map, and Set when it comes to accessing keys. I tested the following three code snippets on JSBEN.CH. Objects const object = {}; for (let i = 0; i < 10000; ++i) { object[`key_${i}` ...

What is the reason behind the improved performance I experience in Chrome with the Developer Console open?

Currently, I am developing a small canvas game completely from scratch using pure JavaScript. This game utilizes a 2D lighting algorithm that is akin to the one found here. It features only one light source and 25 polygons, resulting in approximately 30,0 ...

Enhancing Promises.all with extra parameters

Looking to dive into promises, eager to learn. Here is an array of shopIds I'm working with: let shopIdsArray = ['shop1','shop2','shop3']; Additionally, there's an external promise call: getProducts(shopId, ' ...

Ensuring Data Integrity with JavaScript Form Validation

Ensure that if text box A is filled in, text box B must also be filled in before submitting. Vice versa, if text box B is filled in, make sure text box A has data as well. Is it possible to loop this check for multiple text boxes? For example, if row A o ...

Closing WebSocket connection after sending data

I came across an interesting blog post titled Experimenting with Node.js and decided to try setting it up on my own using the author's provided gist. Unfortunately, I encountered some issues. After further investigation, I discovered that even though ...

Steps to resolve the days.map error:

My map function is, days.map((val)=>val) Upon consoling the days prop, I receive the following output: [Array(7)] 0: (7) ['', '', '', 'Wednesday', '', '', 'Saturday'] length: ...

The onclick function in the Navbar div fails to work for inner elements

Within my navbar, there is a .dropbtn div that I want to trigger a dropdown function when clicked. However, only the text "TOTAL" seems to activate this function onclick. The <span> and <i> elements inside the .dropbtn do not respond to clicks ...

Is there a way to adjust the pivot point of a cone scale in three.js?

I am trying to resize a cone that is generated using THREE.CylinderGeometry. My goal is to make it longer and have it grow in the direction of the negative z-axis, but I've noticed that currently it's growing in both negative and positive directi ...

Expanding Material Ui menu to occupy the entire width of the page

I'm encountering an issue with a menu I created where I can't seem to adjust its height and width properly. It seems to be taking up the full width of the page. import React, { Component } from "react"; import Menu from "@material-ui/core/Menu"; ...