1
<li> 
<button> 
<span>software</span> 
<value>high risk</value> 
</button> <button> 
<span>hardware</span> 
<value>moderate risk</value> 
</button> <button> 
<span>software</span> 
<value>low risk</value> 
</button> 
<button> 
</li>

I have written

//*[contains(@value, 'moderate risk']//preceding::span

Tried with Chropath but it says "This element might be inside iframe from different src. Currently ChroPath doesn't support for them."

Since its a practice, I saved it as html file

KunduK
  • 32,888
  • 5
  • 17
  • 41
JayB
  • 13
  • 5

2 Answers2

1

value is tag here not the attribute

Try below xpath.

//*[contains(text(), 'moderate risk')]//preceding-sibling::span
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Isn't `/preceding-sibling::span` just enough ? – E.Wiest May 14 '20 at 03:37
  • Working with both // and / before Preceding. one clarification on why "value" is tag and not attribute. you mean value tag is same as span tag here bcoz I see both the text on same button in html file. Am unfamiliar with value tag and so far used it as an attribute. – JayB May 14 '20 at 17:26
  • @JayB : Here `value` is a tag like `span` under parent `button`. The value can be an attribute for element like `input` or `button` like if say html `` here value is an `attribute` But your case it is `tag`. – KunduK May 14 '20 at 17:58
0

I am able to locate with the below xpath as well which is similar to the one posted by @kunduk.

//*[contains(text(), 'moderate risk')]/preceding::span[1]

JayB
  • 13
  • 5