Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reading "disabled" property through Node#disabled? and Node#[] methods

  • Loading branch information...
commit 4e73aec4143b65a4f757abd4717bfa737f5207e1 1 parent 304de88
Vasily Reys authored jferris committed
View
6 lib/capybara/driver/webkit/node.rb
@@ -6,7 +6,7 @@ def text
def [](name)
value = invoke("attribute", name)
- if name == 'checked'
+ if name == 'checked' || name == 'disabled'
value == 'true'
else
value
@@ -53,6 +53,10 @@ def visible?
invoke("visible") == "true"
end
+ def disabled?
+ self['disabled']
+ end
+
def path
raise Capybara::NotSupportedByDriverError
end
View
17 spec/driver_spec.rb
@@ -118,6 +118,7 @@
<div id="display_none">
<div id="invisible">Can't see me</div>
</div>
+ <input type="text" disabled="disabled"/>
<script type="text/javascript">
document.write("<p id='greeting'>he" + "llo</p>");
</script>
@@ -243,6 +244,10 @@
subject.find("//p").first.tag_name.should == "p"
end
+ it "reads disabled property" do
+ subject.find("//input").first.should be_disabled
+ end
+
it "finds visible elements" do
subject.find("//p").first.should be_visible
subject.find("//*[@id='invisible']").first.should_not be_visible
@@ -256,6 +261,7 @@
<html><body>
<form action="/" method="GET">
<input type="text" name="foo" value="bar"/>
+ <input type="text" id="disabled_input" disabled="disabled"/>
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
<input type="checkbox" name="uncheckedbox" value="2"/>
<select name="animal">
@@ -377,6 +383,17 @@
unchecked_box.set(false)
unchecked_box['checked'].should_not be_true
end
+
+ let(:enabled_input) { subject.find("//input[@name='foo']").first }
+ let(:disabled_input) { subject.find("//input[@id='disabled_input']").first }
+
+ it "knows a disabled input is disabled" do
+ disabled_input['disabled'].should be_true
+ end
+
+ it "knows a not disabled input is not disabled" do
+ enabled_input['disabled'].should_not be_true
+ end
end
context "form events app" do
View
11 src/capybara.js
@@ -31,9 +31,16 @@ Capybara = {
},
attribute: function (index, name) {
- if (name == "checked") {
+ switch(name) {
+ case 'checked':
return this.nodes[index].checked;
- } else {
+ break;
+
+ case 'disabled':
+ return this.nodes[index].disabled;
+ break;
+
+ default:
return this.nodes[index].getAttribute(name);
}
},
Please sign in to comment.
Something went wrong with that request. Please try again.