All I am getting from Browser.execute is a big fat Undefined for everything

Using custom JavaScript in Nightwatch, I am retrieving various values from a web page.

browser.execute(function () {
    priceValues = {
        total: document.querySelectorAll('someLocator').innerText,
        individualPrice: document.querySelectorAll('someLocator').innerText,
        discount: document.querySelectorAll('someLocator').innerText,
    };
    return priceValues;
}, [], function (result) {
    totalPrice = result.value.total;
    individual = result.value.individualPrice;
    discountPrice = result.value.discount;
});

An issue I'm encountering is that in some tests, the discount value is not available, resulting in undefined. However, this is causing the other two values, total and individualprice, which do have values, to also become undefined. Can anyone help me identify what I might be doing wrong here?

Answer №1

I successfully achieved my goal using the code snippet provided below:

browser.execute(function () {
    priceValues = {
        total: document.querySelectorAll('someLocator').innerText,
        individualPrice: document.querySelectorAll('someLocator').innerText,
    };
    var discount = document.querySelectorAll('someLocator'),

    if (discount && discount.innerText) {
        priceValues.discount = discount.innerText;
    }
    return priceValues;
}, [], function (result) {
    totalPrice = result.value.total;
    individual = result.value.individualPrice;
    discountPrice = result.value.discount;
});

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

getStaticProps function in Next.js fails to execute

My [slug].js file includes two Next.js helper functions, getStaticPaths and getStaticProps. These functions are exported and create the path posts/[slug]. I have also added a post file named hello.json. However, when I try to access localhost:3000/posts/he ...

How can I effectively handle extensive data parsing from a file using JavaScript?

Looking to optimize data parsing in JavaScript for a large file? I'm currently using JSON parse for a 250MB file, but it's too slow. Is there a faster method to extract a high volume of data without iterating through every character? The file con ...

The Angular date picker is overly verbose in its data output regarding selected dates and requires optimization

Using Angular 5, I have integrated a specific npm package for handling dates import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime'; The problem arises when trying to send data to the server in this required format only ...

Modifying the appearance of radio buttons using jQuery

I'm new to jQuery and I'm finding it challenging. Currently, I have a set of three radio buttons with the third button already prechecked. My aim is to change the CSS class of the checked button, making it similar to an unchecked button with the ...

Encountered error message: "Cannot assign argument of type '() => () => boolean' to parameter of type 'EffectCallback'"

I recently started working with TypeScript. I encountered an issue when attempting to utilize useEffect in TypeScript within a React context, Error: Argument of type '() => () => boolean' is not assignable to parameter of type 'Effec ...

How to modify values in a JSON array using JavaScript

Currently, I am facing an issue with displaying dates properly on the x-axis of a graph created using Highcharts. To solve this problem, I need to parse the dates from the JSON response. Despite my attempts to manipulate the JSON date, I have not been able ...

What could be the reason behind the malfunction of query manipulation?

I created a handler factory function for managing an API, which includes a populate method to fill in a field in the database. However, I encountered an issue where my populate method was not working when using query manipulation. let query = await ...

Unexpected behavior when using ng-if within ng-repeat

I am trying to use a repeater to display views in an accordion, with the requirement that the views be conditionally loaded. I attempted to add an ng-if condition to check if current == true on the repeater's elements, but it does not seem to work as ...

Unable to transfer information from an HTTP post request to the JavaScript controller in ExpressJS

I am currently working with React on the frontend and Express.js on the backend. I am trying to send a simple POST request with JSON data from the frontend to the backend. The request body includes {title: "some title", content: "some content"}. However, w ...

An online platform designed to assess the functionality and performance of various websites

Is it possible to find a platform or website that can execute test cases against another REST server? The ideal scenario would involve specifying instructions like: perform a PUT request on this specific URI, using a certain authentication method, providin ...

Why is the reverse sticky navbar not visible after the position changes from fixed to static?

Scenario In the setup, I've implemented a reverse sticky navbar where it remains in position:fixed at the top. However, once the top of a specific div container touches the bottom of the navbar, I switch it to position:static using jQuery. Challenge ...

What is the best way to invoke a component method from an event listener of a different component using ($on)?

I recently came across information on Non-Parent-Child Communication at https://v2.vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication, which explains the concept of using bus events to communicate between components. However, I'm still ...

How can you determine if the browser window is close to the bottom edge?

I have implemented infinite scrolling in my react app and I have a function that is supposed to detect when the user reaches the bottom of the page: const [isFetching, setIsFetching] = useState(false); // Trigger When Reaching Bottom of Page const handl ...

The rendering of the input dropdown control in Angular JS is experiencing difficulties

I am currently using your Angular JS Input Dropdown control, and I have followed the code example provided on your demo page in order to implement the control on a specific page of my website built with PHP Laravel. However, I have encountered an issue dur ...

What is the best method for snapshot testing a component that includes nested components?

I am currently testing a component that contains a nested component using Redux. To test this, I am utilizing shallow rendering. Below is the code for my test: describe("Header", () => void it("renders correctly", () => { const renderer = new ...

jQuery conceal input field after it has been displayed

I've created an HTML form with two different sections for search purposes. The first section displays basic fields, and by clicking on "Advanced Search" (in my case, "Расширенный поиск"), additional fields are revealed. Everything work ...

Navigating through route parameters and application logic

There is an endpoint / which may receive different get parameters for oAuth and logging in to an app. A function called queryAction has been created to handle these requests. Platforms like express can route at the path level but not the res.query level, ...

Manipulating front matter metadata when reading/writing a markdown file in Node.js

I have a large collection of markdown files that I need to update by adding new data to their front matter metadata. Currently, the file structure looks like this: --- title: My title here --- Markdown content here My goal is to include an id property ...

Getting the value of a cell in a grid using grid coordinates with Selenium

CSS <div id="model" class="mobile handsontable htRowHeaders htColumnHeaders" style="height: 100%; overflow: hidden;" data-originalstyle="height: 100%; overflow: hidden;"> <div class="ht_master handsontable"><div class="wtHolder" style ...

What is the best way to reduce the size of a Base64/Binary image in Angular6

I utilized the Ngx-Webcam tool to capture images from my camera. My goal is to obtain both high quality and low quality images from the camera. Although this library provides me with Base64 images, it offers an option to reduce the size using imageQuality ...