def smooth_scroll_until_element_in_view(driver, element):
    """Smoothly scroll up or down until an element is in view."""
    driver.execute_script(
        "arguments[0].scrollIntoView({behavior: 'smooth'});", element
    )
    return driver