Q:

How do I use method in this script?

I am using ruby-cucumber for automation. The steps are as follows:
Then    I click on "Add this" link
Then    I click on "Next" link

This is the script:
Then(/^I click on "Add this" link$/) do
  @driver.find_element(:link, "Add this").click
end

How should I modify the code so that I can use it both for "Add this" & "Next" repeatedly? Any help/comments is appreciated.

A:

Then(/^I click on "([^"]*)" link$/) do |link|
  @driver.find_element(:link, link).click
end

This will then match anything e.g.
Then    I click on "Add this" link
Then    I click on "Next" link
Then    I click on "Foobar" link

