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


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


I am having an issue with a Semantic-UI dropdown component that uses the html select component and can solve with visible = false as shown below:

select 'Male', from: :user_gender, visible: false

      

0


source


Use the text value of the label. In the example below, you should useselect call_status.name, from: 'Call Status'

<label>Call Status</label>
<select class="form-control" id="call_status_id" name="call[status_id]">

      

0


source







All Articles