Retrieving values from multiple inputs in NightwatchJS

Can nightwatchjs be used to retrieve values from multiple inputs simultaneously?

I am looking to verify the values of several input fields at once.

Your help is much appreciated.

Answer №1

Indeed, multiple input values can be retrieved:

The first option involves using callback methods (not recommended):

var text, text2, text3; // ...
browser.getValue('#inputField1', function (result) {
  text = result.value;
  browser.getValue('#inputField2', function (result) {
    text2 = result.value;
    browser.getValue('#inputField3', function (result) {
      text3 = result.value;
      browser.getValue('#inputField4' + text3, function (result) {
        console.log(text, text2, text3) // your code 
      });
    });
  });
});

Alternatively, you can utilize the perform() API from the document (recommended):

var text, text2, text3;
browser
  .getValue('#input', function (result) {
    text = result.value;
    browser.getValue('#inputField2', function (result) {
      text2 = result.value;
    });
  })
  .perform(function () {
    browser.getValue('#inputField3', function (result) {
      console.log(text2, text 1) // they do exist here 
      text3 = result.value;
    });
  });

For more information, refer to Nightwatch's documentation on Perform

Answer №2

To retrieve text or values, you can utilize either the getText or getValue method as shown in the following examples:

this.demoTest = function (browser) {
  browser.getText("#main ul li a.first", function(result) {
    this.assert.equal(typeof result, "object");
    this.assert.equal(result.status, 0);
    this.assert.equal(result.value, "nightwatchjs.org");
  });
};

this.demoTest = function (browser) {
  browser.getValue("form.login input[type=text]", function(result) {
    this.assert.equal(typeof result, "object");
    this.assert.equal(result.status, 0);
    this.assert.equal(result.value, "enter username");
  });
};

For more information on these methods, refer to the API documentation:Text API reference

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

AngularJS Object Comparison: A Comprehensive Guide

My form initiates a GET request to the server upon loading, receiving data that is stored in 'master' and then copied to 'local' as shown below. $scope.dirty = false; init(data); function init(data) { $scope.master = angular.copy ...

Node accurately handles and displays errors, such as validation errors, in a precise manner

I am currently restructuring our code base to incorporate promises. Below are two blocks of sample code: user.service.js export function updateUserProfileByUsername(req, res) { userController.getUserByUsername(req.params.username) .then((userProfile ...

AngularJS filter that retrieves only values that have an exact match

In my AngularJS application, I have a checkbox that acts as a filter: Here is the data being used: app.controller('listdata', function($scope, $http) { $scope.users = [{ "name": "pravin", "queue": [{ "number": "456", "st ...

No data returned from API call in Next.js and Strapi

Recently, I encountered an issue with my Next.js frontend application that fetches data from a Strapi backend. Despite seeing requests being made in the Strapi developer logs, the retrieved data is empty. Below is a snippet of my Next.js code: import { us ...

Feeling lost about arrow functions in JavaScript

Here is the code I am currently using to increment the value of intVariable using window.setInterval. var Arrow = (function () { function Arrow() { this.intVariable = 1; this.itemId = -1; this.interval = 25; } Arrow.p ...

The ElementNotInteractableException from selenium.common.exceptions was triggered because the element was unresponsive when attempting to input text

Having trouble entering text into the email field on . I tried using WebDriverWait but it didn't work. Any help is appreciated. import time import datetime import random from selenium.webdriver.chrome.options import Options from selenium import webdri ...

I am unable to scroll the page in headless mode while using geckodriver with selenium in a docker container

My attempt to use selenium with geckodriver in headless mode within a docker container running Ubuntu 18.04 has hit a snag. Here is the code I am working with: while True: driver.execute_script("window.scrollTo(0, document.body.scrollHeight);" ...

Issue with my JavaScript code for customizing checkboxes: the else condition is not being triggered

I'm currently in the process of customizing my own version of "checkboxes" by styling label elements and moving the actual checkbox off-screen. This is the approach I decided to take based on the design and functionality requirements presented to me. ...

Selenium tips for clicking an element located within several nested iframes

When attempting to click the element within the iframe in the RedBus web application, I encountered a Selenium timeout error stating "no such frame element". I have tried switching frames using id, name, and index but none of them were successful. WebDri ...

Mobile page scroll appears to be disabled due to the Vue range slider

Within my VUE application, I've implemented a range slider component that allows users to view different values as they drag the slider. Everything seems to be functioning correctly, but I've encountered an issue where the mobile version of the p ...

Using jQuery .animate() leading to erratic input movements

I am currently utilizing jQuery's .animate() feature to create a smooth animation effect on the width of a <div> element when a child <input> is in focus. Nevertheless, I'm encountering an issue where the input field jumps up and down ...

Tips for inserting an element into every tier of a multi-layered array

I am faced with a challenging task of assigning an id field to objects within an array that has infinite levels. The rule is simple - for every level, the ID should correspond to the level number starting from 1. { "name": "Anything2&quo ...

What methods can I employ to utilize preg_match with jQuery?

Is it possible to validate a phone number in jQuery using preg_match? I have tried the following code without success: if (!preg_match("/^[0-9]{3}-|\s[0-9]{3}-|\s[0-9]{4}$/", phone.val() )) { phone.addClass("needsfille ...

Is it possible to refresh the JSViews data that is underneath using an onclick event?

I have created a photo gallery using a JSViews template which includes upvote and downvote buttons. When these buttons are clicked, it triggers a database update to increase the score. However, I am facing an issue with updating the Score field in the HTML ...

Guide on linking navigation to various buttons on the Angular menu

I am looking to enhance the functionality of my left menu buttons by adding a navigation path to each one (excluding the main menu). The menu items' names are received as @Input. I have set up a dictionary mapping all the items' names to their r ...

How can I only replace every second occurrence in a JS string?

Looking for help with JavaScript: "a a a a".replace(/(^|\s)a(\s|$)/g, '$1') I thought the result would be '', but it's showing 'a a' instead. Can someone explain what I'm missing? To clarify, I want to r ...

Why won't the div move when I click it?

Could you please explain why my JavaScript code isn't functioning as expected? The intended behavior is for the 'mark' div to move to the current mouse coordinates upon clicking within the map. ...

"Clicking on the hamburger menu causes the webpage to reset its scroll

I recently integrated a mobile hamburger menu into my website, which is primarily built around a single page. However, I noticed that whenever I open the menu, it automatically scrolls to the top of the page regardless of where you were previously scrollin ...

Tips for avoiding the push method from replacing my items within an array?

Currently, I am diving into Typescript and VueJS, where I encountered an issue with pushing elements to my array. It seems to constantly override the 'name' property. Let me share the code snippet causing this problem: const itemsSelectedOptions ...

Encountering an NPM ELIFECYCLE error when attempting to start the node server with the

After following the instructions on deploying test-bot on IBM Watson from this link https://github.com/eciggaar/text-bot, I encountered errors while attempting to deploy the code locally using CLI foundry. My setup includes Node.js version 6.10.3 and npm ...