Skip to content

Instantly share code, notes, and snippets.

@jsmucr
Last active June 11, 2021 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmucr/a2207b20c0712f09a51d68dbfddd5023 to your computer and use it in GitHub Desktop.
Save jsmucr/a2207b20c0712f09a51d68dbfddd5023 to your computer and use it in GitHub Desktop.
How to create switch in xpath
<root>
  <selector>3</selector>
  <value1>A</value1>
  <value2>B</value2>
  <value3>C</value3>
  <other>BAZINGA!</other>
</root>
/root/(
  selector[text()='1']/following::value1,
  selector[text()='2']/following::value2,
  selector[text()='3']/following::value3,
  other
)[1]
Selector value Return value
1 A
2 B
3 C
something else BAZINGA!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment