def _is_scrolled_into_view(driver, element, fully_in_view=True):
    """Returns True if the element is scrolled into view, False otherwise

    Currently, Selenium doesn't offer a means of getting an element's location
    relative to the viewport, so using JavaScript to determine whether the
    element is visible within the viewport.

    :param driver: Selenium WebDriver object
    :param element: WebElement for the element to check
    :param fully_in_view: (Default = True) If True, check that the element is
        fully in view and not cut off. If False, check that it's at least
        partially in view

    :return: True if the element is scrolled into view, False otherwise
    """
    # the JavaScript used to check if the element is in view.
    script_string = '''
    return function(el, strict) {
        var rect = el.getBoundingClientRect();
        var elemTop = rect.top;
        var elemBottom = rect.bottom;

        if (strict)
            var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
        else
            isVisible = elemTop < window.innerHeight && elemBottom >= 0;
        return isVisible;
    }(arguments[0],arguments[1])
    '''
    return driver.execute_script(script_string, element, fully_in_view)