0

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.

2 Answers2

1

Select the first matching element:

//strong[@data-issue-type-field][text()='Template: ']/../span[1]
  • Doesn't work, try with the other word: "Save Locally: " and the result is not the next element. – Joao Gonçalves Jun 27 '19 at 09:44
  • Of course, for a different problem a different solution might be necessary. This approach only works if the `span` you are looking for is the *first*. Use any of the other approaches. –  Jun 27 '19 at 09:48
1

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:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133