Get text content of html element using xpath
This is html content
<p class="ref Hover">
<b class="Hover Hover Hover Hover Hover">Mfr Part#:</b>
MC34063ADR2G<br>
<b>Mounting Method:</b>
Surface Mount<br>
<b>Package Style:</b>
SOIC-8<br>
<b>Packaging:</b>
REEL<br>
</p>
Using the below xpath, I can only get "Mfr Part #:".
//div[@id='product-desc']/p[2]/b[1]/text()
//div[@id='product-desc']/p[2]/b[1]
But I want "Mfr Part #: MC34063ADR2G"
+4
4 answers
You can use the following-siblingaxis to get the text node following the element <b>that you have already selected, for example, the current context element is an element <b>:
following-sibling::text()[1]
or using full XPath:
//div[@id='product-desc']/p[2]/b[1]/following-sibling::text()[1]
+2