Why is contains(text(), "string" ) not working in XPath?

Viewed 1472

I have written this expression //*[contains(text(), "Brand:" )] for the below HTML code.

<div class="info-product mt-3">
  <h3>Informazioni prodotto</h3>


  Brand: <span class="brand_title font-weight-bold text-uppercase"><a href="https://mammapack.com/brand/ava">Ava</a></span><br> SKU: 8002910009960<br> Peso Lordo: 0.471 kg <br> Dimensioni: 44.00 × 145.00 × 153.00 mm<br>

  <p class="mt-2">
    AVA BUCATO A MANO E2 GR.380</p>
</div>

The xpath that I have written is not working I want to select Node that contains text Brand:. Can someone tell me my mistake?

1 Answers

Your XPath,

//*[contains(text(), "Brand:")]

in XPath 1.0 will select all elements whose first text node child contains a "Brand:" substring. In XPath 2.0 it is an error to call contains() with a sequence of more than one item as the first argument.

This XPath,

//*[text()[contains(., "Brand:")]]

will select all elements with a text node child whose string value contains a "Brand:" substring.

See also

Related