Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Make sure nodes hidden with css rule visibility: hidden returns fal…
Browse files Browse the repository at this point in the history
…se on `visible?`
  • Loading branch information
timurvafin committed Oct 23, 2012
1 parent 32db848 commit 3bab97d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/driver_spec.rb
Expand Up @@ -217,13 +217,17 @@ def in_iframe_request?
<head>
<style type="text/css">
#display_none { display: none }
#visibility_hidden { visibility: hidden }
</style>
</head>
<body>
<div class='normalize'>Spaces&nbsp;not&nbsp;normalized&nbsp;</div>
<div id="display_none">
<div id="invisible">Can't see me</div>
</div>
<div id="visibility_hidden">
<div id="invisible_with_visibility">Can't see me too</div>
</div>
<input type="text" disabled="disabled"/>
<input id="checktest" type="checkbox" checked="checked"/>
<script type="text/javascript">
Expand Down Expand Up @@ -387,6 +391,7 @@ def in_iframe_request?
it "finds visible elements" do
driver.find("//p").first.should be_visible
driver.find("//*[@id='invisible']").first.should_not be_visible
driver.find("//*[@id='invisible_with_visibility']").first.should_not be_visible
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/capybara.js
Expand Up @@ -153,8 +153,10 @@ Capybara = {
visible: function (index) {
var element = this.nodes[index];
while (element) {
if (element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("display") == 'none')
var style = element.ownerDocument.defaultView.getComputedStyle(element, null);
if (style.getPropertyValue("display") == 'none' || style.getPropertyValue("visibility") == 'hidden')
return false;

element = element.parentElement;
}
return true;
Expand Down

0 comments on commit 3bab97d

Please sign in to comment.