Using Nightwatch.js to extract the value from an input field and incorporate it into the following step

I am currently attempting to execute a Nightwatch script that will access a URL, retrieve a value from an input field, and then utilize that value on the next page.

Take a look at the code snippet below:

var conf = require('../../nightwatch.conf.BASIC.js');

module.exports = {
    'nightwatch flow': function (browser) {
        var first_name;
        browser
            .url('http://example:3000')
            .getValue('input[name="first_name"]', function(result){
                first_name = result.value;
            })
            .setValue('input[name="amount"]', 101)
            .click('input[name=continue]')
            .clearValue('input[name="first_name"]')
            .setValue('input[name="first_name"]', first_name)
            .click('button[name=next]')
            .end();
    }
};

In the line

setValue('input[name="first_name"]', first_name)
, the value appears as "undefined."

The issue arises from the fact that the first_name parameter is being updated within a callback function. I require the setValue function to utilize the updated value properly. Any assistance would be greatly appreciated.

Answer №1

After much trial and error, I have managed to come up with a solution:

var conf = require('../../nightwatch.conf.BASIC.js');

var full_name;

module.exports = {
    'nightwatch process': function (browser) {
        browser
            .url('http://example:3000')
            .getValue('input[name="full_name"]', function(result){
                full_name = result.value;
            })
            .setValue('input[name="amount"]', 101)
            .click('input[name=continue]')
            .clearValue('input[name="full_name"]')
            .setValue('input[name="full_name"]', "", function(){
                browser.setValue('input[name="full_name"]', full_name)
            })
            .click('button[name=next]')
            .end();
    }
};

The key is to utilize the browser.setValue function within a callback to achieve the desired outcome.

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

Utilizing the principles of object orientation in Javascript to enhance event management

After attempting to modularize my JavaScript and make it object oriented, I found myself struggling when dealing with components that have multiple instances. This is an example of how my code currently looks: The HTML file structure is as follows: & ...

Guide on choosing options from a dropdown menu using Selenium WebDriver

I am attempting to choose the Channel on a webpage from a Drop Down Box using the Selenium Webdriver in Python. The HTML code is provided below: <iframe id="page" frameborder="0" src="DashBoard.htm" onfocus="this.blur()" scrolling="no" cellspacing=" ...

Stop Bootstrap Modal from displaying with the help of an ajax error

Is there a way to prevent the Modal from appearing when an ajax call returns an error? I've tried using the code snippet below, but it didn't work for me. Here's how my ajax call is set up: $.ajax({ url: url, data: data, dataTyp ...

Unleashing the Power of Javascript in Selenium with Java (featuring PrimeFaces)

Recently, I discovered that JavaScript seems to be malfunctioning in my Selenium Tests written in Java. The reason behind this issue remains a mystery to me. Any ideas on how to tackle this roadblock? ((JavascriptExecutor) driver).executeScript("retur ...

The method element.isDisplayed() is indicating a false value even though the element is visibly present on the screen

element.isDisplayed() is returning false even though the element is visible on the screen, causing issues with clicking on it. I attempted to use the code below, but without success. Actions cursor = new Actions(driver); cursor.moveTo ...

Can a custom spellchecking feature be integrated into an HTML textarea?

Question: I am wondering if it is feasible to incorporate a personalized spell checking feature into a Textarea field. Background: Currently, I am utilizing the b-form-textarea component from bootstrap-vue to present a textarea where users can input a li ...

What is the process for changing the behavior when the checkbox is selected or deselected?

Hello everyone. I'm facing a challenge that I can't seem to overcome. I'm trying to adjust the behavior of an element using the ".on/.off" methods based on whether a checkbox is ticked or not. Can someone provide some guidance on how to achi ...

ng-class not updating using a combination of object and string

I am just starting to learn angular js and I recently came across the ng-class directive. Below is an example of how I have used it: ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed), 'bold-row-Class' : ...

The use of refs on Function components in SVG is not supported. Any attempts to access the ref will result in an

I am currently working on integrating a navigation bar component using an SVG image in Next.js. While attempting to import and utilize the SVG image, I encountered an error that I couldn't resolve. I tried using Emotion JS to create and use the SVG, ...

Building a web proxy with node.js and express

I'm currently in the process of designing a personalized web proxy using JavaScript to allow users to surf the internet through a designated website, similar to this . One challenge I encountered is transferring the response from a URL back to the us ...

Utilizing the length property of arrays for mathematical computations

I'm currently exploring the possibility of achieving this using javascript. In my scenario, I have an array named cart that consists of objects with product.quantity, and I aim to incorporate the value of cart.length in a calculation. However, I cons ...

Unable to get Grunt watch task to function properly

Recently delving into Grunt, I've encountered some issues with the watch feature. While my tasks work fine when run directly from the CLI, the watch command seems to be causing trouble. Could there be any problems with my current Gruntfile setup? mod ...

Ways to retrieve the clicked item's index in a jQuery collection without using the index() method

Is there a way to obtain the index of clicked elements easily? var $inputs = $("input"); $inputs.click(function() { console.log($(this).index()) }); This method correctly works for the structure below: div>(input+input+input) However, I am encoun ...

Accessing Zillow

I'm having trouble logging into Zillow. I can't seem to locate the email or password input fields to enter my credentials. The script was functioning properly before, but now it's unable to find the elements. When passing a driver object wi ...

I'm unable to locate the import library option on Eclipse. Even though I've included the necessary library in the build configuration path

` <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <model ...

capturing the null object in JavaScript

I am having trouble determining if the object is null or not an object. I tried using this line in an if condition to solve it, but it's not working. However, I keep getting an ERROR message stating "object is null or not an object". var preWynum = ...

Prevent Date Selection in jqGrid for Inline Editing

I am currently using jqGrid 4.4.4 and have implemented a date picker for a column that defaults to today's date. However, I need it to only default to today's date in the add modal pop-up. When editing a record inline, I do not want the date to a ...

Guide to displaying a standard view in Vue.js 3

I am attempting to display a default view/route immediately upon Vue.js loading. Currently, the page loads with the header and footer visible, but there is a brief delay before the homepage content is displayed. This results in the footer moving up to meet ...

Can anyone offer guidance on how to properly parse the " " character after consolidating an array into a

When working with Vue.JS, I encountered a situation where I had an array in an object that was parsed as a string like this: destination: item[1].destination.join('\n') Upon checking console.log(obj), the output appeared as follows: destin ...

What is the best way to develop a unique animation for every v-card?

Is there a way to customize each animation so that it is specific to the selected v-card? Right now, when one card is clicked, all of them play the same animation. data: () => ({ show: true, images: [ {url:require('@/assets/london. ...