Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Migrate to SeleniumHQ 3 #11
Browse files Browse the repository at this point in the history
- Add scrollIntoView method
  • Loading branch information
cezarypiatek committed Apr 24, 2017
1 parent 1edace4 commit 832494e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Src/MvcPages/SeleniumUtils/SeleniumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ internal static bool IsElementClickable(this RemoteWebDriver driver, IWebElement
", element);
}

internal static void ScrollIntoView(this RemoteWebDriver driver, IWebElement element)
{
driver.ExecuteScript(@"
if(typeof arguments[0].scrollIntoView == 'function'){
arguments[0].scrollIntoView();
}
", element);
}


public static int GetPageHeight(this RemoteWebDriver driver)
{
var scriptResult = driver.ExecuteScript("return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");
Expand Down Expand Up @@ -283,6 +293,7 @@ public static void ClickOn(this RemoteWebDriver driver, IWebElement expectedElem
driver.ScrollToY(expectedElement.Location.Y + expectedElement.Size.Height);
Thread.Sleep(500);
}
driver.ScrollIntoView(expectedElement);
driver.WaitUntil(SearchElementDefaultTimeout, (d) => driver.IsElementClickable(expectedElement));
expectedElement.Click();
if (originalScrollPosition != null)
Expand Down

0 comments on commit 832494e

Please sign in to comment.