I use this function to scroll to an element:
public function scrollIntoView($elementId) {
$function = <<<JS
(function(){
var elem = document.getElementById("$elementId");
elem.scrollIntoView(false);
})()
JS;
try {
$this->getSession()->executeScript($function);
}
catch(Exception $e) {
throw new \Exception("ScrollIntoView failed");
}
}
The js function "scrollIntoView" takes the parameter "alignWithTop". In my method it is set to false making the element align with the bottom. If you need it to align with the top of the scroll area - then set it to true.