This will work:
webdriver.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -window.innerHeight / 2);", element);
The method scrollIntoView
can scroll the element at the top or at the bottom of the view with the default being at the top:
https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView
Below are the supported options:
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
Try without passing any argument :
webdriver.executeScript("arguments[0].scrollIntoView();", element);
So you could scroll it at the bottom instead:
webdriver.executeScript("arguments[0].scrollIntoView(false);", element);
You could also scroll it at the top and then by a 1/4th of the height of the view:
webdriver.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -window.innerHeight / 4);", element);
Or just below a element , eg fixed header:
webdriver.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -arguments[1].offsetHeight);", element, header);
Reference: Scroll Element into View with Selenium