Expressions XPath Absolues vs Relatives
Dans cette vidéo, nous expliquons la différence entre XPath Absolu et XPath Relatif.
XPath Absolu :
Non recommandé pour les projets en temps réel
Utilisé principalement à des fins d'apprentissage
XPath Relatif :
Recommandé pour une utilisation en temps réel
Plus flexible et fiable
Exemples d'XPath Absolu :
html : /html
head : /html/head
title : /html/head/title
body : /html/body
p tag : /html/body/p
Premier paragraphe : /html/body/p[1]
Deuxième paragraphe : /html/body/p[2]
Paragraphe avec id égal à para1 : /html/body/p[@id='para1']
Paragraphe avec class égal à sub : /html/body/p[@class='sub']
Paragraphe avec class égal à main : /html/body/p[@class='main']
Paragraphe avec id égal à para2 : /html/body/p[@id='para2']
Paragraphe avec id égal à para1 et class égal à main : /html/body/p[@id='para1'][@class='main']
Paragraphe avec id égal à para2 et class égal à sub : /html/body/p[@id='para2'][@class='sub']
Point clé :
L'XPath Absolu aide à comprendre la structure, mais l'XPath Relatif est meilleur pour l'automatisation en temps réel.