Alpha Romeo
Alpha Romeo

Reputation: 84

Xpath selecting data after the <br/> tag

I have this html:

<div class="sys_key-facts">
  <p>
   <strong>Full-time </strong>1 year<br>
   <strong>Part-time</strong> 2 years
  </p>
</div>

I want to get the value of Part-time(After Part-time), which is:

2 years</p>

My Xpath code is :

//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")]][preceding-sibling::br]/text() 

but this is returning empty. Please let me know where I am mistaking. Thanks

Upvotes: 1

Views: 1041

Answers (1)

Andersson
Andersson

Reputation: 52665

The problem is that p[preceding-sibling::br] means that paragraph has line break sibling while br is actually a child of p - not a sibling

So you can update your XPath as

//div[@class="sys_key-facts"]/p[strong[contains(text(), "Part-time")] and br]/text()[last()]

or try below XPath to get required output:

//div[@class="sys_key-facts"]//strong[.="Part-time"]/following-sibling::text()

Upvotes: 3

Related Questions