public void XPathQueryUsageTest() { // Prepare an HTML code var code = @" <div class='happy'> <div> <span>Hello!</span> </div> </div> <p class='happy'> <span>World</span> </p> "; // Initialize a document based on the prepared code using (var document = new HTMLDocument(code, ".")) { // Here we evaluate the XPath expression where we select all child SPAN elements from elements whose 'class' attribute equals to 'happy': var result = document.Evaluate("//*[@class='happy']//span", document, null, XPathResultType.Any, null); // Iterate over the resulted nodes for (Node node; (node = result.IterateNext()) != null;) { Output.WriteLine(node.TextContent); // output: Hello // output: World! } Assert.True(document.QuerySelectorAll("div").Length > 0); } }