Don't check node ancestors for CSS visibility setting

This commit is contained in:
Thomas Walpole 2018-01-04 17:38:22 -08:00
parent 0f548058b7
commit ba33a6bae7
2 changed files with 35 additions and 5 deletions

View File

@ -31,6 +31,18 @@ describe Capybara::Webkit::Node do
<input type="checkbox" name="falsecheckedbox" value="3" checked="false"/>
<input type="text" name="styled" style="font-size: 150%;"/>
</form>
<div id="visibility_wrapper" style="visibility: hidden">
<div id="hidden">Hidden</div>
<div id="visible" style="visibility: visible">Visibile</div>
<div style="visibility: visible">
<div id="nested_visible">Nested Visibile</div>
</div>
</div>
<div id="display_none" style="display: none">
<div id="not_displayed" style="visibility: visible; display: block;">Should not be displayed</div>
</div>
</body>
</html>
HTML
@ -62,5 +74,17 @@ describe Capybara::Webkit::Node do
expect(input["style"]).to eq "font-size: 150%;"
end
end
context "Node#visible" do
it "correctly analyzes visibility CSS" do
expect(driver.find_css('#hidden').first.visible?).to be false
expect(driver.find_css('#visible').first.visible?).to be true
expect(driver.find_css('#nested_visible').first.visible?).to be true
end
it "correctly analyzes display: none CSS" do
expect(driver.find_css('#not_displayed').first.visible?).to be false
end
end
end
end

View File

@ -249,12 +249,18 @@ Capybara = {
},
isNodeVisible: function(node) {
while (node) {
var style = node.ownerDocument.defaultView.getComputedStyle(node, null);
if (style.getPropertyValue('display') == 'none' || style.getPropertyValue('visibility') == 'hidden')
return false;
var style = node.ownerDocument.defaultView.getComputedStyle(node, null);
// Only check computed visibility style on current node since it
// will inherit from nearest ancestor with a setting and overrides
// any farther ancestors
if (style.getPropertyValue('visibility') == 'hidden' || style.getPropertyValue('display') == 'none')
return false;
node = node.parentElement;
// Must check CSS display setting for all ancestors
while (node = node.parentElement) {
style = node.ownerDocument.defaultView.getComputedStyle(node, null);
if (style.getPropertyValue('display') == 'none' )
return false;
}
return true;
},