0
votes

I know there are tons of this type of question, but I've tried a few solutions with no luck.

Here is the source for the Dropdown:

<select style="display: none;" name="Select_Company" id="Select_Company" class="company-list-select">

And then below is just a bunch of normal option values: IE:

<option value="2">Generic Company</option>

(This is repeated of course).

So here's what I've tried:

select('GenericCompany', :from => 'Select_Company')
select('Select_Company')select('Generic Company', :from => 'Select_Company')

also I tried (Which I imagine doesn't work because the "Please select a company" text is technically an option:

select 'ACME', from: "Please Select a Company"

All of them result in a Unable to find Element error. Any ideas? Im not really sure what to try.

This is using Capybara and Rspec, the rest of the code is fine as It works up to here (Where we go to select from the dropdown). The only thing I can think that's odd (I didn't write this site) is that after selected the dropdown class goes to this:

<div id="Select_Company_chosen" title="" style="width: 100%;" class="chosen-container chosen-container-single"><a class="chosen-single" tabindex="-1"><span>Please Select a Company</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input autocomplete="off" type="text"></div><ul class="chosen-results"><li data-option-array-index="0" style="" class="active-result result-selected">Please Select a Company</li><li data-option-array-index="1" style="" class="active-result">
1

1 Answers

2
votes

Looking at your select it has "style=display: none" which would indicate it is not visible on the page. I'm assuming it has been replaced on the page by a JS driven widget which your final line seems to show. Because of this you can't just use select (it only works with real visible <select> elements) and will need to replicate the behavior a user would do. I'm not sure what that is for the widget you're using, but usually something like click on the widget, which makes a ul visible and then click on the visible li you want - something like

page.find('.chosen-drop').click
page.find('li', text: 'the text of the item to select').click