2010-01-05 4 views
1
page.getByXPath("//*[@href='http://www.example.com/index.do/abc/1_*'"); 

Ai-je besoin d'échapper des caractères?Est-ce que xpath a l'air correct?

Je suis en train de faire tous les liens AHREF sur la page qui ont le profil de:

http://www.example.com/index.do/abc/1_ 

si ceux-ci doivent tous être récupérés:

http://www.example.com/index.do/abc/1_asdf-asdfasdf 
http://www.example.com/index.do/abc/1_223 
http://www.example.com/index.do/abc/1_as.php 
http://www.example.com/index.do/abc/1_2222233 

Répondre

4

Il n'y a pas jokers dans XPath. Vous voulez quelque chose comme ceci:

page.getByXPath("//*[contains(@href,'http://www.example.com/index.do/abc/1_')]"); 

Cela repose sur the contains function. Vous pouvez également utiliser la fonction starts-with:

//*[starts-with(@href,'http://www.example.com/index.do/abc/1_')] 
+1

Oui, c'est pourquoi c'est dans ma réponse avec 'contains'. – Welbog

0

Si vous utilisez XPath 1.0, vous ne pouvez pas faire correspond à caractère générique (ou une expression régulière) de cette façon. (Mise à niveau vers 2.0 peut permettre que)

Dans ce cas, je vous suggère de faire un 'contient' test pour le préfixe

// un [contient (@href, 'http://www.example.com/index.do/abc/1_')]

(note, je limite la sélection à quelques tags)

0

Voir si votre bibliothèque XPath prend en charge starts-with(string1,string2) et utilisation:

page.getByXPath("//*[starts-with(@href, 'http://www.example.com/index.do/abc/1_')"); 

en outre, vous ne pouvez pas remplacer * par a?

+0

J'utilise java 1.6 – mrblah