Skip to content
Browse files

Allow interaction with invisible elements

  • Loading branch information...
1 parent 4d954b7 commit 02f2a8ab73a2e69eb023ba1d48ee4000360cd213 @jferris jferris committed Mar 9, 2012
Showing with 1 addition and 50 deletions.
  1. +0 −12 lib/capybara/driver/webkit/node.rb
  2. +1 −38 spec/driver_spec.rb
View
12 lib/capybara/driver/webkit/node.rb
@@ -1,9 +1,5 @@
class Capybara::Driver::Webkit
class Node < Capybara::Driver::Node
-
- class ElementNotDisplayedError < StandardError
- end
-
NBSP = "\xC2\xA0"
NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding)
@@ -33,7 +29,6 @@ def set(value)
end
def select_option
- check_visibility(self)
invoke "selectOption"
end
@@ -47,13 +42,10 @@ def unselect_option
end
def click
- check_visibility(self)
invoke "click"
end
def drag_to(element)
- check_visibility(self)
- check_visibility(element)
invoke 'dragTo', element.native
end
@@ -122,9 +114,5 @@ def browser
def multiple_select?
self.tag_name == "select" && self["multiple"] == "multiple"
end
-
- def check_visibility(element)
- raise(ElementNotDisplayedError, "This element is not visible so it may not be interacted with") unless element.visible?
- end
end
end
View
39 spec/driver_spec.rb
@@ -713,13 +713,10 @@
<div id="change">Change me</div>
<div id="mouseup">Push me</div>
<div id="mousedown">Release me</div>
- <div id="invisible-mouseup" style="display:none;">You can't push me</div>
- <div id="invisible-mousedown" style="display:none;">You can't release me</div>
<form action="/" method="GET">
<select id="change_select" name="change_select">
<option value="1" id="option-1" selected="selected">one</option>
<option value="2" id="option-2">two</option>
- <option value="2" id="invisible-option" style="display:none;">three</option>
</select>
</form>
<script type="text/javascript">
@@ -741,7 +738,6 @@
});
</script>
<a href="/next">Next</a>
- <a href="/next" id="hidden" style="display:none;">Not displayed</a>
</body></html>
HTML
[200,
@@ -750,7 +746,7 @@
end
end
- it "clicks a visible element" do
+ it "clicks an element" do
subject.find("//a").first.click
subject.current_url =~ %r{/next$}
end
@@ -782,39 +778,6 @@
subject.find("//*[@class='triggered']").size.should == 1
end
-
- context "raises error when" do
- it "tries to click an invisible element" do
- expect {
- subject.find("//*[@id='hidden']").first.click
- }.to raise_error(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
- end
-
- it "tries to drag an invisible element to a visible one" do
- draggable = subject.find("//*[@id='invisible-mousedown']").first
- container = subject.find("//*[@id='mouseup']").first
-
- expect {
- draggable.drag_to(container)
- }.to raise_error(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
- end
-
- it "tries to drag a visible element to an invisible one" do
- draggable = subject.find("//*[@id='mousedown']").first
- container = subject.find("//*[@id='invisible-mouseup']").first
-
- expect {
- draggable.drag_to(container)
- }.to raise_error(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
- end
-
- it "tries to select an invisible option" do
- option = subject.find("//option[@id='invisible-option']").first
- expect {
- option.select_option
- }.to raise_error(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
- end
- end
end
context "nesting app" do

0 comments on commit 02f2a8a

Please sign in to comment.
Something went wrong with that request. Please try again.