Reputation: 5005
I'm very new to Cucumber/Capybara/Ruby/Selenium and I'm just trying to set a simple field with a value. I'm finding the field with a special selector and then trying to set it:
Capybara.add_selector(:filter_field) {xpath { |field_name| ".//div[contains(@class,'#{field_name}')]//input" }}
def fill_in_field(field_name, value)
field = find(:filter_field, field_name)
field.set(value)
end
undefined method `^' for "1":String (NoMethodError) ./features/support/ui_interface_react.rb:271:in `fill_in_field'
The error occurs on the line field.set(value)
. I know that value is a string and field is a #<Capybara::Node::Element>
. What am I doing wrong?
Upvotes: 0
Views: 1942
Reputation: 449
You should declare function in top of file because ruby execute in top to bottom fasion like this
def fill_in_field(field_name, value)
field = find(:filter_field, field_name)
field.set(value)
end
Capybara.add_selector(:filter_field) {xpath { |field_name| ".//div[contains(@class,'#{field_name}')]//input" }}
Upvotes: 0
Reputation: 49950
You're using selenium, and I'm guessing the field element you're finding is a checkbox, which takes true
or false
when calling set, not a string.
Upvotes: 2