0
votes

I'm begginer to write xpath expression,facing an issue for captureing string (or) text of next to the <b> Tag sibling element like,

<div id="product-desc" class="green-box">
    <p class="ref">
        <b class="">Mfr Part#:</b>
        "STM6520AQRRDG9F"
        <br class="">
        <b class="">Mounting Method:</b>
        "Surface Mount"
        <br class="">
        <b class="">Package Style:</b>
        "TDFN-8"
        <br class="">
        <b class="">Packaging:</b>
        "REEL"
        <br class="">    
    </p>
 </div>

In Above html code how should i get the text xpath expression i.e ("STM6520AQRRDG9F") next to <b> element.I tried with following ways

//*[@id="product-desc"]/p[2]/b[1]/following-sibling::text()

can any one suggest me to get currect xpath expression of getting text xapth Expression.

Thanks for advance regards.

1
it should be p[1] ... - hek2mgl
The title of your question is utterly unhelpful - it could be the title of any question that is related to XPath. Please find a more meaningful title. - Mathias Müller
I changed the title. - Michael Kay

1 Answers

2
votes

As hek2mgl has mentioned, the text you'd like to find is in the first p element of that div. Also, to avoid any surprising results, you should select only the first following text node that is a sibling.

One way to do it is

//*[@id="product-desc"]/p[1]/b[1]/following-sibling::text()[1]

and the result will be

[EMPTY LINE]
"STM6520AQRRDG9F"
[EMPTY LINE]