Requête XPath recherchant un élément avec un texte spécifique
Question
Étant donné la structure XML suivante
<html>
<body>
<div>
<span>Test: Text2</span>
</div>
<div>
<span>Test: Text3</span>
</div>
<div>
<span>Test: Text5</span>
</div>
</body>
</html>
Quelle est la meilleure requête XPath pour localiser un span
dont le texte commence par Test
?
La solution
//span[starts-with(.,'Test')]
Références:
http://www.w3.org/TR/xpath/ # function-commence-avec
https://developer.mozilla.org / fr-fr / docs / Web / XPath / Fonctions / commence avec
Autres conseils
L'option valide est également:
//span[contains(.,'Test')]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow