Capybara claim nothing selected from dropdown list

I'm trying to claim that none of the options from my drop-down list were selected, but the following failures:

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 verify that my selected input has not selected anything. How can i do this?

+4
source share
2 answers

You can get the select value by calling .valueon Capybara::Node::Element.

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

or

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

Perhaps easier:

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

This works, at least with capybara 2.14.0 and possibly earlier.

+1
source

Source: https://habr.com/ru/post/1585104/


All Articles