How to click on a table row using capybara & rspec

I am using the request specification for my rails application with capybara. There is something like in my code:

%table
  %tbody
     %tr{"on_click" => "location.href='some_link'"}
       %td="Some attribute"
       %td="Some attribute"
       %td="Some attribute"
       %td="Some attribute"

This way I am making the whole line pressed. I want to write a request specification with capybara for this function, but I don't know how to do it. Can someone help me with this?

thank

+3
source share
2 answers

Maybe you should first learn testing in rails. Check this! http://railscasts.com/episodes/275-how-i-test , this is really useful. You can specify a trclass (say) .trand do

page.find(:css, ".tr").click()

I hope this works, worked in my case!

+3
source

, , :

page.find(:xpath, "//table/tbody/tr").click

, JavaScript, :js => true . JavaScript - . :

:

# Note that opening page by clicking on row requires JavaScript
describe "when user clicks on first row", :js => true do

  let(:first_account_listed) { Account.order(:name).first }

  before { page.find(:xpath, "//table/tbody/tr").click }

  it { should have_selector('title', text: 'Account Details') }

end
+4

All Articles