From 3c8ad255adc05d5ca2ad3f92bd31c2879bf32f34 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Wed, 21 Nov 2012 14:40:36 -0500 Subject: [PATCH] Ensure the attribute exists before returning its value --- lib/capybara/webkit/node.rb | 6 +++++- spec/driver_spec.rb | 2 +- src/capybara.js | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/capybara/webkit/node.rb b/lib/capybara/webkit/node.rb index acbd8c1..cfa1b4b 100644 --- a/lib/capybara/webkit/node.rb +++ b/lib/capybara/webkit/node.rb @@ -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 diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 7595409..84d7bff 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -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 diff --git a/src/capybara.js b/src/capybara.js index 6462399..83ebfa7 100644 --- a/src/capybara.js +++ b/src/capybara.js @@ -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("/"); },