fix(Page.waitForSelector): "visible" option should check parent visibility (#1354)

This patch starts checking for boundingClientRect to make sure that the
element is visible.
This commit is contained in:
JoelEinbinder
2017-11-10 15:44:01 -08:00
committed by Andrey Lushnikov
parent 44d1e834a4
commit f8d19e79e7
2 changed files with 26 additions and 2 deletions

View File

@@ -502,8 +502,16 @@ class Frame {
if (!waitForVisible && !waitForHidden)
return true;
const style = window.getComputedStyle(node);
const isVisible = style && style.display !== 'none' && style.visibility !== 'hidden';
const isVisible = style && style.visibility !== 'hidden' && hasVisibleBoundingBox();
return (waitForVisible === isVisible || waitForHidden === !isVisible);
/**
* @return {boolean}
*/
function hasVisibleBoundingBox() {
const rect = node.getBoundingClientRect();
return !!(rect.top || rect.bottom || rect.width || rect.height);
}
}
}