For selecting dropdown using capybara : getting undefined method
click_button' for nil:NilClass (NoMethodError) ./features/pages/cm_dash_board.rb:187:inchoose_role' ./features/pages/cm_dash_board.rb:147:in set_role' ./features/step_definitions/cm_dash_board_steps.rb:58:in/^
Method:
def choose_role(role_name)
click_button CHOOSE_ROLE
find(ROLEDROPDOWN).all('li').select{|role| role.text == role_name}.first.click_button
end
Feature file:And(/^I assign "([^"]*)" role to the "([^"]*)" user$/) do |email, role_name|
@sw.cm_dash_board.set_role(email,role_name)
end
That error tells you that
find(ROLEDROPDOWN).all('li').select{|role| role.text == role_name}isn't matching any elements. The firstfindis finding something (or you'd have a different error), but then eitherall('li')is finding no elements or the select is filtering out all elements.As a side node, you really shouldn't be using
selectfor this anyway and should instead be specifying it in yourallcall likeThat may well still fail, but at least the error will tell you why it's failing