DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on • Updated on

click link in Capybara

πŸ”— Parent Note

πŸ‘ Way1: Usual way.

Capybara::Node::Actions#click_link is easy.

You can just type the text. This example click the link of dev.to edit link.

click_link('EDIT')

Also, you can do this.

click_link(href: "/n350071/my-capybara-note-2gp3/edit")

But, if the page has 2 or 3 of same link? You will face to Ambiguous match error.

πŸ‘ Way2: Workaround

You can use find and find_all method.

find('a[href="/n350071/my-capybara-note-2gp3/edit"]') 

find_all('a[href="/n350071/my-capybara-note-2gp3/edit"]').each do
  # do something
  # back
  page.go_back
end

If you want to click button,

click_button('SUBMIT')

Top comments (0)