Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created May 14, 2015 19:41
Show Gist options
  • Save tncbbthositg/aa41eeac8db41f201be3 to your computer and use it in GitHub Desktop.
Save tncbbthositg/aa41eeac8db41f201be3 to your computer and use it in GitHub Desktop.
Detecting visibility of element in viewport
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