xpath and html value (javascript)

Let's say I want to check if "xpath html value" is equal to some text in a website.

Like:

html/body/div/div[7]/table/tbody/tr[2]/td value = "some text" 

How do I get it?

Answers


You can use document.evaluate to do this:

var value = document.evaluate('html/body/div/div[7]/table/tbody/tr[2]/td', document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;

Have a look here for some more information on how to set up an iterator and iterate through a number of nodes, in case you need to get the value of more than just one td in the tr.


Need Your Help

OneToOneField with ForeignKey

django django-models

I have the following situation: