XPath using JScript

I'm a beginner with Selenium and I'm curious about how the value in the text box is loaded when there's no value visible in the HTML tag:

<input type="text" name="qty" id="qty" maxlength="5" value="" title="Qty" class="quantity-input qty" 

Could it be coming from JavaScript?

<script type="text/javascript">
    jQuery(document).on('click','.quantity-plus',function(){
        var qty = jQuery.trim(jQuery('#qty').val());
        if(qty < 99999)
        {   
        var moq = jQuery('input[name=opinions]:checked').attr('data-moq');
        var incrementquantity = jQuery('input[name=opinions]:checked').attr('data-incrementquantity');
        var incrementmode = jQuery('input[name=opinions]:checked').attr('data-incrementmode');
        var qty = jQuery.trim(jQuery('#qty').val());
        jQuery('.moqerror').html('');
        if(Number(qty) >= Number(moq) && parseInt((qty-moq)%incrementquantity) == 0)
        {
            var newqty = parseFloat( parseFloat(qty) + parseFloat(incrementquantity));
            jQuery('#qty').val(newqty);
            updateEstimatePrice();
        }

Answer №1

According to the code, the value attribute is being set using the val() function.

var newqty = parseFloat( parseFloat(qty) + parseFloat(incrementquantity));
jQuery('#qty').val(newqty);

I'm a bit puzzled by the mention of 'XPath' in the title of the question, which leads me to believe I may be misunderstanding something.

UPDATE: Regarding the Selenium query:

It appears to be quite broad, but here's how I would approach it:

Prerequisites:

  1. Jasmine testing framework
  2. promises
  3. webdriverjs's control flow using promises
  4. How angular protractor uses promises

If you're comfortable with those requirements:

First, set up Selenium with protractor (which can be complex), and then you could potentially try this approach (untested):

describe("Checking selectall, ", function() {
  it("exists,", function() {
    var qty = element(By.css('input#qty'));
    expect(browser.isElementPresent(qty)).toEqual(true);
    it("clicks loads with a value", function() {
      qty.getAttribute("value").then(function(data) {
          return console.log("qty.value", 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

PhantomJS Alert: UnresolvedPromiseRejectionNotice

My main objective is to extract data from a website using Node.js. I have successfully managed to gather information using the request package, however, the website I am targeting contains dynamic content which cannot be accessed solely with request. Aft ...

retrieving serialized object from an ajax request sent to the web server

As a newcomer to web development, I decided to create an ASP.NET project with a web API to test my skills. In the process, I crafted a controller and some JavaScript files as follows: Controller: namespace MyNamespace.Controllers { public c ...

What is the process for obtaining information about a website's SSL certificate expiration, issuer, and other details using Selenium with

I am looking to fetch the certificate information of a webpage that is displayed in the Chrome browser. The specific details I need include: Issued to Issued by Validity I am unsure of the next steps or where to find the certificate. I attempted to locat ...

Exploring ways to compare and update values in an array of objects using JavaScript

I have a situation where I need to compare the names and values of two arrays filled with objects. const array1 = [ { name: 'Sarah', value: null }, { name: 'Michael', value: null } ] const array2 = [ { na ...

Display Issue with Header Row in React Data Table Component - Full Text Not Visible

Hey there! I've been working with a neat npm package called react-data-table-component. However, I've run into a bit of trouble trying to adjust the width of the table header text. Take a look at the issue here: https://i.sstatic.net/AzqNw.png ...

The combination of AddEventListener in the parent and postMessage in the iframe is ineffective

As I delve into the Stripe documentation to develop a new feature, I have encountered an issue regarding the communication between a webpage and an iframe. The code in index.html: <!DOCTYPE html> <body> parent<br> <iframe src="./ ...

The querySelector function is now encountering errors due to a change in the data

Currently, I am utilizing a query selector to retrieve an input when a user selects different buttons. Initially, the buttons had options such as: 8x10 inch 12x16 inch 20x24 inch However, I made changes to the options format like so: 8" x 10" ...

Tips for updating the background color of a specific row

I have a piece of code that I am trying to modify with a specific condition. If {row.BB} is less than or equal to 100, I want to change the background color of the row with this value to red. Can someone help me achieve this? The code is linked to a data ...

When using Specflow with .NetCore (MSTest), a request for the .feature.cs file is prompted during the build

Recently, I encountered an issue while trying to create Specflow tests with .NetCore and MSTest. According to Specflow, it does not generate any .feature.cs file for Feature files. However, when I attempted to build my application, I received an error st ...

What is the best way to load an index.js file within a plugin framework?

I currently have an isolated index.js file located at plugins/some_plugin/index.js After attempting to run require(path_to_index.js) in my application, I encounter a 'cannot find modules' error message. This issue is understandable as the "some ...

Guide for integrating images in React Native

I am struggling to display images in a carousel properly. I attempted to require them using JSON like this {"Image": require("$PATH")} or in a js file within the ParallaxImage tag, but nothing seems to work... Item Creator _renderItem ...

Setting state back to default following the conditional rendering of a React component

Whenever the save button is clicked, I aim to display a snackbar component by updating the showSnackbar state to true. To achieve this in React, it's just a simple conditional check in the main render method. The snackbar I'm using here automatic ...

Failure of event watcher on dynamically updated content

Any help would be greatly appreciated! :) I am currently using JavaScript to dynamically add fields to a document, but I have noticed that the event listener only works on predefined fields. For instance, in the code snippet below, the 'lozfield&apo ...

Interacting with a Flash button through selenium Webdriver

Looking to automate the widget found at using Selenium Web Driver. I've managed to create an AutoIt script for uploading files, but I'm having trouble clicking the 'Add File' button on the provided URL. Can anyone offer assistance with ...

Can the value of a key be changed to match the condition in a find() query when using Mongoose?

Having been well-versed in Oracle, I was thrown into a project requiring the use of a MongoDB database. Utilizing mongoose to connect to my MongoDB, my main query is whether it is possible to match a find condition before executing a query. For example, if ...

Turning a JSON string into interpolation within an Angular application

I received a JSON response that looks like this: { someText: "Order in {000} 12pm PST for early shipping"; cutofftime : "10000000" } What is the most effective way to replace the '{000}' with the dynamic value stored in &quo ...

Transmit information to PHP via JSON with Cross Domain communication

My code is server1 and PHP code is server2. These servers are not connected. What issues can arise from this setup? var req = new XMLHttpRequest(); req.open("POST", "http://www.example.com/form/data.php", true); req.setRequestHeader("Content-type", "ap ...

Create a hierarchical tree structure using a string separated by dots

I am struggling with organizing a tree structure. :( My goal is to create a tree structure based on the interface below. export type Tree = Array<TreeNode>; export interface TreeNode { label: string; type: 'folder' | 'file'; ...

Error encountered while attempting to locate element via its identification

Hi there! I am pretty new to using Selenium and could really use some guidance. I've been trying to click the button labeled "continue" on a specific page but keep encountering this error: "NoSuchElementException: no such element: Unable to locat ...

Looking to configure Selenium to continuously click a specified target until a specific element becomes visible?

I'm currently working on developing an automated checkout system for a website. My goal is to have it click the "add to cart" button repeatedly until the "checkout" button becomes visible. However, I am facing a challenge as the current setup only all ...