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'
value == 'true'
else
value
if invoke("hasAttribute", name) == 'true'
value
else
nil
end
end
end

View File

@ -773,7 +773,7 @@ describe Capybara::Webkit::Driver do
end
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
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) {
return "/" + this.getXPathNode(this.nodes[index]).join("/");
},