Ionut Flavius Pogacian
Ionut Flavius Pogacian

Reputation: 4811

How to extract Element value using JavaScript from DOM if i know the XPATH?

I have 2 Xpaths from a DOM :

id("viewproduct-emagoo")/div[@class="big-box"]/div[@class="container-top mb10"]/div[@class="left-content"]/div[@class="container-detalii-produs"]/h2[1]

and

id("viewproduct-emagoo")/div[@class="big-box"]/div[@class="container-top mb10"]/div[@class="left-content"]/div[@class="container-detalii-produs"]/form[1]/div[1]/div[@class="info-box-produs"]/div[@class="disponibilitate-produs"]/div[@class="pret-produs"]/span[1]

I want to extract the Element/s value from one of the above xpaths using JAVASCRIPT.

If someone can find an old article about this, pls give me the link.

Upvotes: 0

Views: 187

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

Assuming you have an XPath expression selecting an element node with Mozilla or Opera or Chrome or Safari then simply do

document.getElementById("form_selected_product_name").value
  = lookupElementByXPath(value).textContent;

Upvotes: 1

Related Questions