fivetwentysix
fivetwentysix

Reputation: 7485

Using Capybara w/ Selenium, how would I click a table row?

Would simply like to know if there's an alternative to click_link / click_button that can be used with any element as some of my clickable elements are not standard html clickables such as tr elements, but they still contain href attributes.

Javascript enabled.

Upvotes: 3

Views: 2287

Answers (4)

subiet
subiet

Reputation: 1399

I have tried the javascript solution in past, it works in the sense that the button do gets clicked, but cucumber fails to recognise it as a completed step.

Upvotes: 0

kinster
kinster

Reputation: 339

I had the same situation with a html month view, I had to choose a day of month. I kept it as simple as I could and this is only one way of doing this.

# Choose July 22 (at this point in time)
assert page.has_css? '#calendar'
within '#calendar' do
  find('td', :text => '22').click 
end

Upvotes: 2

idlefingers
idlefingers

Reputation: 32067

Are you using cucumber? Not sure if it's any use to you, but here's a cucumber step definition for clicking anything with selenium:

Then /^I click "(.+)"$/ do |locator|
  selenium.click locator
end

Upvotes: 0

Nerian
Nerian

Reputation: 16197

Use Javascript then:

page.execute_script("$('whatever_you_want').click()");

Upvotes: 3

Related Questions