protected void MoveElementToMiddleOfPage(IWebElement element) { //scroll element to middle of the page string script = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + "var elementTop = arguments[0].getBoundingClientRect().top;" + "window.scrollBy(0, elementTop-(viewPortHeight/2));"; WebDriverHelper.ExecuteJavascript(script, element); }
private void WaitUntilDocumentHasFullyLoaded() { try { //Selenium webdriver executes to quickly at times, this method will ensure that //the page has always been fully loaded before each action WaitUntil(wd => WebDriverHelper.ExecuteJavascript("return document.readyState").ToString() == "complete"); } catch { //Swallow exception - ignore exceptions thrown by Javascript } }
public void ScrollDown() { WebDriverHelper.ExecuteJavascript("window.scrollTo(0, document.body.scrollHeight - 150)"); }