Joao Gonçalves
Joao Gonçalves

Reputation: 31

Xpath - How to get the text of next line at same level java

I need to get the text (Bulk Template) after the text()='Template: '.

<div class="description secondary-text">
    <strong data-issue-type-field="name">Template: </strong>
    <span class="description secondary-text">Bulk Template</span>
    <strong data-issue-type-field="name">Save Locally: </strong>
    <span class="description secondary-text">c:\</span>
</div>

I've tried with this XPath expression:

//strong[@data-issue-type-field][text()='Template: ']/../span

but it retrieved two results.

Upvotes: 0

Views: 931

Answers (2)

Dmitri T
Dmitri T

Reputation: 168157

The "next" element at the "same level" in XPath world is called following-sibling therefore the XPath expression you're looking for is:

//strong[contains(text(),'Template')]/following-sibling::span

enter image description here

More information:

Upvotes: 1

user11044402
user11044402

Reputation:

Select the first matching element:

//strong[@data-issue-type-field][text()='Template: ']/../span[1]

Upvotes: 1

Related Questions