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)