Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath query to select all href attributes of <a> tag, which 'class' attribute equals specified string

Tags:

xpath

I don't know why following query doesn't work:

//a/@href[@class='specified_string'] 
like image 549
l245c4l Avatar asked Apr 22 '10 14:04

l245c4l


People also ask

What will be the XPath expression to select?

XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.

Can you use XPath expression used to select the target node and its values?

XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.


1 Answers

Try it the other way round:

//a[@class='specified_string']/@href 

After all, class is an attribute of the <a> element, not an attribute of the href attribute.

like image 83
ndim Avatar answered Oct 22 '22 01:10

ndim