2017-04-27 6 views
0

Ich versuche mit Capybara die Select Method zu verwenden. Ich habe alle angebotenen Lösungen ausprobiert, besonders die aus dieser Stackoverflow Discussion.Capybara select_option gefunden, aber nicht ausgewählt

Ich habe die folgende Auswahl mit dem country_select gem. Dies ist der html.erb Code aus dem Formular:

<%= f.country_select(:country, {include_blank: 'Select a country', selected: "Select a country"}, {class: 'form-control', :id => "country_select"}) %> 

Der HTML vom Browser wie folgt aussieht:

<select class="form-control" id="country_select" name="user[country]"><option value="">Select a country</option> 
    <option value="AF">Afghanistan</option> 
    <option value="AX">Åland Islands</option> 
    <option value="AL">Albania</option> 
    other staff... 

Wenn ich debuggen die Auswahlmethode aus dem Capybara GEM file actions.rb row 183 (wo ich eine Haltepunkt), die Ausgabe ist korrekt.

def select(value, options={}) 
    binding.pry 
    if options.has_key?(:from) 
     from = options.delete(:from) 
     find(:select, from, options).find(:option, value, options).select_option 
    else 
     find(:option, value, options).select_option 
    end 
    end 

So ist die Zeile:

find(:select, from, options).find(:option, value, options) 

kehrt

=> #<Capybara::Node::Element tag="option" path="/html/body/div/div[2]/div/div/div/div/div/form/div[4]/select/option[2]"> 

Welches ist die richtige Option wählen ist. Wie Sie sehen können, ist die option[2] Afganistan, aber es sieht aus wie .select_option funktioniert nicht.

Ich denke, Capybara öffnet die Auswahlbox nicht, bevor das Feld ausgewählt wird. Ich habe Capybara (2.13.0) und Schienen 5.0.2

Vielen Dank Fabrizio Bertoglio

Antwort

Verwandte Themen