7
votes

Comment accéder à l'élément en utilisant Watir et XPath

J'ai du code HTML qui ressemble à ceci:

<h1 id="header">Header</h1>


0 commentaires

6 Réponses :


5
votes
browser.element_by_xpath("//h1[@id='header']").click
Sources:
http://wiki.openqa.org/display/WTR/XPath
http://zeljkofilipin.com/2007/07/03/find-element-by-xpath/

4 commentaires

Cela ne fonctionne pas pour moi. Il ne semble plus y avoir ollement_by_xpath


Je pense que l'élément_by_xpath a été obsolète récemment.


Je viens de vérifier, ollement_by_xpath a été supprimé de wattir-webdriver dans la version 0.5.1: GITUB.COM/WATIR/WATIR-WETIRVER/BLOB/MASTER/CHANGES.MD#051


On dirait qu'il est remplacé par .Element (: xpath => "str") , n'a pas encore été testé. Gracieuseté de groups.google.com/forum/#!Topic/watir- Général / C6ORVY7QALW



5
votes
browser.h1(:xpath, "//h1[@id='header']").click

0 commentaires

0
votes

n'utilise pas xpath, mais cela fonctionne:

browser.h1(:id, "header").click


0 commentaires

1
votes

Pas non plus XPath, mais fonctionne:

browser.h1(:html, /header/).click


1 commentaires

Je suppose : html désigne la source HTML de l'élément, correct? Donc, dans votre exemple correspondant à un motif?



11
votes

Après wattir-webdiver 0.5.1 Sélection de l'élément aléatoire avec un XPath a été mis à jour pour:

browser.element(:xpath => "//h1[@id='header']").click


0 commentaires

0
votes

Un autre exemple en utilisant XPATH ici:

browser.element xpath: "//div/cite[contains(.,'some text')]/ancestor::div[@class='rc']/h3/a"


0 commentaires