Curious about learning the Xpath?

This is the HTML content

<dd id="_offers2" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer" class="wholesale nowrap ">
    <span itemprop="price" class="Hover   Hover   Hover">$46.29</span>
    / each
    <meta itemprop="pricecurrency" content="USD" class="">
</dd>

To extract the values "$46.29" and "/each" individually, the Xpath for both needs to be obtained.

Answer №1

In order to obtain the amount of $46.29 :

selector = //dd/span[@itemprop='price']

var spanElement = document.evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

After retrieving the span element, you can extract the text content of the element using :

spanElement.textContent

To retrieve the /each :

Follow the same steps as mentioned above to obtain /each. This time, you will have to target the dd element instead of span, hence your xpath will be //dd

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

Why does the Angular page not load on the first visit, but loads successfully on subsequent visits and opens without any issues?

I am currently in the process of converting a template to Angular that utilizes HTML, CSS, Bootstrap, JavaScript, and other similar technologies. Within the template, there is a loader function with a GIF animation embedded within it. Interestingly, upon ...

manipulating child element's innerHTML with javascript

Is there a way to change my icon from expand_more to expand_less in the code below? <li class="dropdown-bt" onclick="dropdown('content');"> <a>dropdown-content <i class="material-icons">expand_more</i></a> </ ...

Tips for enabling unrestricted unencoded HTML in XmlNode or XmlElement with XmlSerializer

Looking for a solution to generate an XML element that can handle a string of text containing HTML or other valid XML elements. Here's an example: "Test text with <strong>custom nodes</strong> that shouldn't be encoded" I've at ...

How can you customize your WooCommerce add to cart functionality using Ajax to set a unique price for your products?

My current challenge involves adding a product to the cart during checkout through an on_click event. The price of this product is calculated dynamically using an external API, causing it to register with a price of 0 in WooCommerce itself. While I have su ...

The PHP script fails to execute within HTML elements

Hey there! I'm currently working on designing my own error page, which involves extracting some data from the URL. At the top of my error.php file, here is the code I have: <?php $error_message = $_GET["error_message"]; if(!$error_message) { ...

What is the best way to align a div right below an image that has been clicked on?

I am designing a website that features social media icons spread out horizontally across the page. When a user clicks on one of these icons, I envision a pop-up window appearing below it, displaying additional information. Here is a visual representation o ...

Troubleshooting textarea resize events in Angular 6

In the development of my Angular 6 application, I have encountered an issue with a textarea element. When an error occurs, an asterisk should be displayed next to the textarea in the top-right corner. However, there is a gap between the textarea and the as ...

The express response fails to include the HTML attribute value when adding to the href attribute of an

When using my Nodejs script to send an express response, I encounter a problem. Even though I set the href values of anchor tags in the HTML response, they are not visible on the client side. However, I can see them in the innerHTML of the tag. The issue ...

issues retrieving array information from datalist using jquery

Struggling to fetch data from an array in a datalist using JQuery, but encountering issues. The array is populated correctly and various loops have been attempted - forEach, for, and while. However, the for and while loops result in an error: Uncaught Sy ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

How to send an email with an attachment using jQuery AJAX and PHP

I have developed a program for sending emails with attachments. Initially, I created it without using ajax and it worked perfectly fine. However, when I tried implementing jQuery ajax, the functionality stopped working. Upon clicking the apply button, noth ...

Notification not appearing in PHP

When working with a specific php file, I am encountering an issue where the alert box I have placed before the header is being ignored and the header is executed directly. Can anyone assist me in resolving this issue? Any help would be greatly appreciate ...

Ways to expand HTML input fields to fill the whole table cell

Currently working on a calculator project and I'm facing an issue with making a HTML button span the entire cell. I've managed to stretch the button horizontally but struggling to get it to fill the cell completely. Curious as to why setting widt ...

Innovative sound system powered by React

I am working on implementing a music player feature on a website where users can select a song and have it play automatically. The challenge I am facing is with the play/pause button functionality. I have created all the necessary components, but there see ...

Exploring the integration of AJAX callbacks with ASP.NET User controls

What is the most effective approach for integrating user controls that require AJAX callbacks? My objectives include: Utilizing browser events (such as drag and drop) to trigger an AJAX notification that can initiate a control event, allowing the code o ...

What is the best way to simulate a click on an anchor tag using JavaScript?

In the setup of my website, there is a div container that includes an <input> element and an <a onclick="DoSomeStuff();" href="#" target="_blank"> element serving as a button. The function DoSomeStuff(); alters the href attribute based on the i ...

Function URL.createObjectURL is not defined in Reactjs

I am currently working on a loadfile function that is supposed to load an image after uploading. However, I am facing an issue with converting it to get its URL path. Whenever I try to do so, I encounter an error saying "URL.createObjectURL is not a func ...

Problems with CSS text scrolling

We have a client who wants a marquee-style scrolling text banner, and I tried using CSS animations to achieve it. However, I encountered some quirks that I'm struggling to fix. If you want to take a look at the issue, here is the link: https://jsfidd ...

Encountering an issue while attempting to input a URL into the Iframe Src in Angular 2

When I click to dynamically add a URL into an iframe src, I encounter the following error message: Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'SafeValue%20must%20use%20%5Bproperty%5D' To ensure the safety of the ...

Determining the type of index to use for an interface

Imagine having an interface called Animal, with some general properties, and then either be a cat or a dog with corresponding properties. interface Dog { dog: { sound: string; } } interface Cat { cat: { lives: number; } } type CatOrDog = Cat | D ...