1

I have the following dropdown menu / select implemented in Angular.js:

<select id="user_accounts" ng-model="account_chosen" 
  ng-options="item.name for item in accounts">
  <option value="">All</option>
</select>

The accounts holds an array of objects: account A, account B, account C, which is rendered on the client-side for the user to see.

On the Capybara RSpec side, I want to integrate a test like so:

select('account A', from: "user_accounts")

However, running the test, I get an "Unable to find option 'account A' " error. How can I configure the test to select an option from the dropdown correctly?

2 Answers 2

2

Suppose you have a driver like phantomjs or selenium you can do these things :

clicking by text selection :

find('#user_accounts').find(:xpath, "option[normalize-space(text())='account A']").select_option

or check wether the selectbox has the textitems :

element=find('#user_accounts')
element.should have_selector(:xpath, "option[normalize-space(text())='account A']")
Sign up to request clarification or add additional context in comments.

Comments

0

You haven't mentioned which Capybara driver you're using, but if your test rely on client-side rendering, you'll need to be sure to use a driver that can execute JavaScript. The default RackTest driver cannot.

See https://github.com/jnicklas/capybara#drivers for instructions on setting the driver to Selenium or another JavaScript-capable option.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.