Wednesday, September 30, 2009

Clicking on links in Webrat using XPath

If for some reason you wanna use XPath instead of CSS Selector to click on a link

# Cucumber step
And I follow "Edit" for "John Woo"

# Using Css Selector
within(%\...\) do
click_link(link)
end

# Using XPath
response.should have_xpath(%\//td[normalize-space(text())="#{name}"]/parent::tr//a[normalize-space(text())="#{link}"]/@id\) do |link_id|
click_link(link_id)
end

No comments:

Blog Archive