Can't find select box with capybara
In my spec, I have
select call_status.name, from: 'call_status_id'
When I do save_and_open_page after or before this command,
<select class="form-control" id="call_status_id" name="call[status_id]">
But when I do this test, I have
Failure/Error: select call_status.name, from: 'call_status_id'
Capybara::ElementNotFound:
Unable to find select box "call_status_id"
I also tried to do
select call_status.name, from: '#call_status_id'
or
select call_status.name, from: 'Call Status Id'
or
select call_status.name, from: 'Call Status'
But I am getting the same error.
+4
source to share
4 answers
Try to wrap your selection in a block within
?
within('//divname') do
select call_status.name, from: '#call_status_id'
end
I cannot give you a reason why your code is not working as it is. I am assuming that you are 100% sure that the ID exists on the page when it works, but that might give you a workaround; it worked for me in similar circumstances.
+2
source to share
You can create a helper under the support folder. ei functions /support/world.rb Add this method to this file:
def select_from_chosen(item_text, options)
page.execute_script("
$('##{options[:from]} option').filter(function () {
return $(this).text() == '#{item_text}';
})[0].selected = true;
$('##{options[:from]}').trigger('liszt:updated');"
)
end
Now you can use this method in step definitions like this:
select_from_chosen('Select call status',from: 'call_status_id')
Hope this helps.
0
source to share