Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:07:07+00:00 2026-06-15T05:07:07+00:00

Given a select control that you wish to have the applicable option selected upon

  • 0

Given a select control that you wish to have the applicable option selected upon form load (by obviously hydrating your model in the controller), how do you determine in an RSpec/Capybara integration test whether the proper option is actually selected?

For example, given the following select control…

<select class="select optional" id="receiving_tally_po_id" name="receiving_tally[po_id]">        
    <option value="10020">PO-10020 - Schoen Inc</option>
    <option value="10018" selected="selected">PO-10018 - Senger, Eichmann and Murphy</option>
</select>

…how would you test that selected=”selected” on the value 10018?

describe "auto-populate with PO information" do
  let!(:po) { FactoryGirl.create(:po) }

  before { visit new_receiving_tally_path(:po => po) }
  # The following checks to see if the option is actually there, but not if it's selected.
  it { should have_xpath "//select[@id = '#receiving_tally_po_id']/option[@value = '#" + po.id.to_s + "' ]" }
end

UPDATE….another stab at it, but it appears to ignore the block items (it says it’s all good even with erroneous info – the reason is probably obvious):

  it "should have the proper PO selected" do
    should have_selector("select#receiving_tally_po_id") do |content|
      content.should_not have_selector(:option, :value => po.id.to_s, :selected => 'selected')
    end
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:07:09+00:00Added an answer on June 15, 2026 at 5:07 am

    try as follow

    it " should have your_value when page loaded" do 
      find_field(field).value.should eq "your_value"
    end
    

    hope it would help

    To fit the above example:

    subject { page }
    ... 
        describe "auto-populate with PO information" do
          let!(:po) { FactoryGirl.create(:po) }
          before { visit new_receiving_tally_path(:po => po) }
          it { find_field('receiving_tally_po_id').value.should eq po.id.to_s }
        end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a repeater that displays a custom user control on a form multiple
Given this SQL: SELECT * FROM mytable ORDER BY mycolumn, RAND() Assuming that mycolumn
I have a simple query to show a given users photos: SELECT pid FROM
I am looking for an sqlite3 command that let's me select entries given by
I have method that is returning IQuerable given below: internal IQueryable<TradeLeads> GetLeadsByCategory(int categoryId) {
I have a CheckedListBox control on my windows form application, which gives a list
To dynamically fill DropDown controls on my HTML Form, I have written code that
I noticed that when I create a GridView that I am given the option
Given that I have an IEnumerable<T> , where T is any object, how can
I have a form in C# with a drop down box. When that drop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.