stephenmurdoch
stephenmurdoch

Reputation: 34623

Capybara assert nothing selected from dropdown

I'm trying to assert that none of the options from my dropdown have been selected, but the following all fail:

assert page.has_select? "franchise_id", selected: nil
assert page.has_select? "franchise_id", selected: false
assert page.has_select? "franchise_id", selected: "Pick a Franchise"

I just want to test that my select input has nothing selected. How can I do that?

Upvotes: 4

Views: 642

Answers (2)

Daniel Fone
Daniel Fone

Reputation: 2905

Perhaps easier:

assert page.has_select? "franchise_id", selected: []

This works at least as of capybara 2.14.0 and perhaps earlier.

Upvotes: 2

max
max

Reputation: 102230

You can get the value of a select by calling .value on a Capybara::Node::Element.

assert_nil page.find("#franchise_id").value

or

# Rails specific
assert_blank page.find("#franchise_id").value 

Upvotes: 4

Related Questions