Ensure the attribute exists before returning its value

This commit is contained in:
Matthew Horan 2012-11-21 14:40:36 -05:00
parent 7ace6dce54
commit 3c8ad255ad
3 changed files with 10 additions and 2 deletions

View File

@ -12,7 +12,11 @@ module Capybara::Webkit
if name == 'checked' || name == 'disabled' || name == 'multiple' if name == 'checked' || name == 'disabled' || name == 'multiple'
value == 'true' value == 'true'
else else
value if invoke("hasAttribute", name) == 'true'
value
else
nil
end
end end
end end

View File

@ -773,7 +773,7 @@ describe Capybara::Webkit::Driver do
end end
it "does not modify the selected attribute of a new selection" do it "does not modify the selected attribute of a new selection" do
monkey_option['selected'].should be_empty monkey_option['selected'].should be_nil
end end
it "returns the old value when a reset button is clicked" do it "returns the old value when a reset button is clicked" do

View File

@ -64,6 +64,10 @@ Capybara = {
} }
}, },
hasAttribute: function(index, name) {
return this.nodes[index].hasAttribute(name);
},
path: function(index) { path: function(index) {
return "/" + this.getXPathNode(this.nodes[index]).join("/"); return "/" + this.getXPathNode(this.nodes[index]).join("/");
}, },