Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Fix destructive methods for selecting options
Browse files Browse the repository at this point in the history
Both `select_option` and `unselect_option` were modifying the
`selected` attribute of their target `<option>` element. This attribute
is meant to be used solely as the marker for which `<option>`(s) is
(are) the default selection(s) in a (multi-)`<select>` element. The
actual _selectedness_ of an `<option>` should be tracked using its
`selected` **property**. Read [the spec][] for more info.

This change removes any code which modified the `selected` attribute of
`<option>` elements, which leaves only the code that modifies the
`selected` property. In addition, `Node#value` needed to be changed to
return `<option>` elements whose selectedness is true rather than just
those with a `selected` attribute.

The tests introduced in the previous commit now pass.

[the spec]: http://dev.w3.org/html5/spec/Overview.html#the-option-element
  • Loading branch information
jasonmp85 committed Feb 12, 2012
1 parent acd6e47 commit 2fef844
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
6 changes: 1 addition & 5 deletions lib/capybara/driver/webkit/node.rb
Expand Up @@ -22,11 +22,7 @@ def [](name)

def value
if multiple_select?
self.find(".//option").select do |option|
option["selected"] == "selected"
end.map do |option|
option.value
end
self.find(".//option").select(&:selected?).map(&:value)
else
invoke "value"
end
Expand Down
2 changes: 0 additions & 2 deletions src/capybara.js
Expand Up @@ -196,13 +196,11 @@ Capybara = {

selectOption: function(index) {
this.nodes[index].selected = true;
this.nodes[index].setAttribute("selected", "selected");
this.trigger(index, "change");
},

unselectOption: function(index) {
this.nodes[index].selected = false;
this.nodes[index].removeAttribute("selected");
this.trigger(index, "change");
},

Expand Down

0 comments on commit 2fef844

Please sign in to comment.