Using Protractor to iterate through and send keys to each element in a given index

Is it possible to loop through and send values to sendKeys(value)?

I have tried various options to solve this problem but with no success.

Numbers.ts

export const Numbers = {
 1: '777',
 2: '777',
 3: '777'
};

Texts.ts

export const Texts = {
  1: '111',
  2: '222',
  3: '333'
};

Code.ts

public async readFromFile(): Promise<void> {
  const numbers: object = Numbers;
  const texts: object = Texts;

  function* generatorNumbersAndTexts(objectNumbers, objectTexts) {
    let i: string;
    let j: string;

    for (i in objectNumbers) {
      for (j in objectTexts) {
        if (objectNumbers.hasOwnProperty(i) &&   objectTexts.hasOwnProperty(j)) {
          yield i;
          yield j;
        }
      }
    }
  }

  for (let indexI of generatorNumbersAndTexts(numbers, texts)) {
    for (let indexJ of generatorNumbersAndTexts(numbers, texts)) {
      texts.hasOwnProperty(indexJ)) {
      await this.clickSendMessage();
      try {
        await this.typeContacts(numbers[indexI]);
      } catch (e) {
        throw new Error(`There is no phone field ${e}`);
      }
      await this.typeMessage(texts[indexJ]);
      await this.sendMessage();
    }
   }
  }

Methods

The following methods were utilized within the readFromFile method.

public async typeContacts(numbers: string): Promise<void> {
  await this.contactField.sendKeys(numbers + ';');
}

public async typeMessage(text: string): Promise<void> {
  await this.messageField.type(text);
}

public async type(text: string): Promise<void> {
  await this.clearInput();
  await this.sendKeys(text);
}

It appears that there may be an issue related to Protractor promises.

Answer â„–1

There was a Protractor issue that needed addressing, and here is the solution:

public async fromJSON(): Promise<void> {
  for (const key in Numbers) {
    if (Numbers.hasOwnProperty(key)) {
      for (const text in Texts) {
        if (Texts.hasOwnProperty(text)) {
          await this.screenshot(`./screens/1${key}.png`);
          await this.clickSendMessage();
          await this.screenshot(`./screens/2${key}.png`);
          await this.typeContacts(Numbers[key.toString()]);
          await this.typeMessage(Texts[text.toString()]);
        }
      }
    }
  }
}

Answer â„–2

Providing a comprehensive answer without access to the functions you are utilizing can be challenging. However, it is indeed feasible to utilize sendKeys() in conjunction with iterating through an object.
Here is an illustration of using sendKeys() within a loop:

it('Should demonstrate a loop', async ()=>{
  let elem = $(''); // Specify the input element where keys will be sent
  let values = {1:'111', 2:'222', 3:'333'}; // Test values
  for(let key in values){
    await elem.sendKeys(values[key]);
  }
}

In this scenario, 111222333 will be sent to elem.

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

Node.js does not allow the extension of the Promise object due to the absence of a base constructor with the required number of type

I'm trying to enhance the Promise object using this code snippet: class MyPromise extends Promise { constructor(executor) { super((resolve, reject) => { return executor(resolve, reject); }); } } But I keep encou ...

Use Angular to trigger a method when the Enter key is pressed, passing the current input text as a parameter

I need to extract the text from an input field and pass it to a method. Here is the code: index.component.html <input type="text" (keyup.enter)="sendData()" /> index.component.ts sendData() { console.log(The text from the input field); } Can ...

JavaScript encountered a ReferenceError: 'a' has not been declared

One interesting feature of my slider is that it uses links like <a id="foo" class="oslide">Chineese Food</a> to navigate through the slides. To make this navigation function properly, I had to include a.href = "#"; in the link's click even ...

Utilize the fetch function to showcase information retrieved from a specific endpoint on a webpage using Javascript

Hey there, I have a Node server with an http://localhost:3000/community endpoint. When I make a GET request to this endpoint, it returns information about three different users in the form of JSON objects. [ { "avatar": "http://localhost:3000/avatars ...

Encountering an issue with React JS Array Filtering: running into the error message "

I am encountering an error stating that includes is not a function, and the record.id is not being recognized in VS Code. I'm not sure where the problem lies? import React, { Component } from 'react' import axios from "axios" export de ...

Why is it that when I use require.js, all my modules appear to be loading at once when the page first

During the development of my single-page backbone app using requirejs, I encountered an issue when deploying to our beta server. The initial page load took around 20 seconds as it had to fetch all the necessary scripts. I initially believed that this dela ...

Challenges with HTML and JavaScript

Struggling to get this code to work properly with Node.js. const express = require('express') const app = express() app.use(express.static('public')) //includes content of public folder app.get('/', function (req, res){ ...

AngularJS Compile directive allows you to specify functions that you want to run in

Can someone assist me in understanding how to call an external function from a built-in compile directive? Here is a code example: http://plnkr.co/edit/bPDaxn3xleR8SmnEIrEf?p=preview This is the HTML: <!DOCTYPE html> <html ng-app="app"> ...

Converting data received from the server into a typescript type within an Angular Service

Received an array of Event type from the server. public int Id { get; set; } public string Name { get; set; } public DateTime Start { get; set; } public DateTime End { get; set; } For Angular and TypeScript, I need to transform it into the following clas ...

using single quotation marks for string keys in a JavaScript object

While working with nodejs, I encountered an issue when creating a list of objects with string keys and numbers as values. Upon logging the list using console.log(), I noticed that some keys had single quotes surrounding them while others did not. For exam ...

NextAuth: JWT callback that returns an object

I've been working on a project using Next.js (11.1.2) + NextAuth (^4.0.5) + Strapi(3.6.8). The Next Auth credentials provider is functioning correctly. However, I need to access certain user information using the session. I attempted to do this by ut ...

Encountered an error while parsing a module in React: Unexpected token

After deciding to incorporate the npm package react-radio-buttons into my project, I encountered an error upon installation and implementation in my component: ./node_modules/react-radio-buttons/index.jsx 80:6 module parse failed: Unexpected token (80:6) ...

Exploring the concept of nested arrays in Angular 2 using Typescript

I'm exploring the possibility of defining an array in Angular 2 that contains multiple other arrays within it. To clarify, here's what I had initially: export class PaymentDetails { account: any[]; bpNumber: number; } The issue with t ...

The conversion from CSV to JSON using the parse function results in an inaccurate

I am having trouble converting a CSV file to JSON format. Even though I try to convert it, the resulting JSON is not valid. Here is an example of my CSV data: "timestamp","firstName","lastName","range","sName","location" "2019/03/08 12:53:47 pm GMT-4","H ...

Utilizing TypeScript with Express.js req.params: A Comprehensive Guide

Having an issue with my express.js controller where I am unable to use req.params The error message being displayed is 'Property 'id' is missing in type 'ParamsDictionary' but required in type 'IParam'.' I need a w ...

Generate a distinct identifier for the select element ID whenever a new row of data is inserted into a table

Although my title accurately describes my issue, I believe the solutions I have been attempting may not be on the right track. I am relatively new to javascript and web development in general, so please forgive me for any lack of technical terminology. Th ...

"Troubleshooting Problems with Scaling in the jQuery Mouse Wheel Plugin

I am currently utilizing this code in conjunction with the following plugin: mouse wheel $('#painter').on('mousewheel', function(e) { cp.scale(2, 2); var e0 = e.originalEvent, delta = e0.wheelDelta || -e0.de ...

Just initiate an API request when the data in the Vuex store is outdated or missing

Currently, I am utilizing Vuex for state management within my VueJS 2 application. Within the mounted property of a specific component, I trigger an action... mounted: function () { this.$store.dispatch({ type: 'LOAD_LOCATION', id: thi ...

Sending data using the AJAX method with integers

Utilizing AJAX to send a high score to a SQLite database's highScores table, the total of the high score must be calculated through a query and then retrieved back from the database. How can I ensure that the score is sent as an integer through AJAX t ...

What is the process of adding an array into a JSON object using the set() function in Firebase?

I am trying to add a new item to my firebase database with a specific JSON object structure: var newItem = { 'address': "Кабанбай батыр, 53", 'cityId': 1, 'courierName': "МаР...