Created
May 14, 2015 19:41
-
-
Save tncbbthositg/aa41eeac8db41f201be3 to your computer and use it in GitHub Desktop.
Detecting visibility of element in viewport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Watir | |
class Element | |
def on_screen? | |
windowHeight = browser.execute_script('return window.innerHeight') | |
elementRect = browser.execute_script('return arguments[0].getBoundingClientRect()', self) | |
elementTop = elementRect["top"] | |
return elementTop >= 0 && elementTop < windowHeight | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment