/// <summary> /// JavaScript method to scroll an element into the view /// </summary> /// <param name="element">Web element</param> /// <param name="x">Horizontal direction</param> /// <param name="y">Vertical direction</param> public static void ScrollIntoView(this IWebElement element, int x, int y) { var driver = SeleniumUtilities.SearchContextToWebDriver(element); ScrollIntoView(element); ExecuteScrolling(driver, x, y); }
/// <summary> /// Drag and drop an item to a destination, plus or minus and X and Y offsets /// </summary> /// <param name="source">Element to drag and drop</param> /// <param name="destination">Where to drop the element, plus or minus the offsets</param> /// <param name="pixelsXOffset">Integer of pixels to be moved (Positive or negative) horizontally</param> /// <param name="pixelsYOffset">Integer of pixels to be moved (Positive or negative) vertically </param> public static void DragAndDropToOffset(IWebElement source, IWebElement destination, int pixelsXOffset, int pixelsYOffset) { Actions builder = new Actions(SeleniumUtilities.SearchContextToWebDriver(source)); // Move to element goes to the top left corner so compensate for that int horizontalOffset = (destination.Size.Width / 2) + pixelsXOffset; int verticalOffset = (destination.Size.Height / 2) + pixelsYOffset; builder.ClickAndHold(source).MoveToElement(destination, horizontalOffset, verticalOffset).Release().Build().Perform(); }
/// <summary> /// Drag and drop an element /// </summary> /// <param name="source">Element to drag and drop</param> /// <param name="destination">Where to drop the element</param> public static void DragAndDrop(this IWebElement source, IWebElement destination) { Actions builder = new Actions(SeleniumUtilities.SearchContextToWebDriver(source)); builder.DragAndDrop(source, destination).Build().Perform(); }
/// <summary> /// Performs a hover over on an element /// </summary> /// <param name="element">The web element</param> public static void HoverOver(this IWebElement element) { Actions builder = new Actions(SeleniumUtilities.SearchContextToWebDriver(element)); builder.MoveToElement(element).Build().Perform(); }
/// <summary> /// Performs a right-click on an element /// </summary> /// <param name="element">The web element</param> public static void DoubleClick(this IWebElement element) { Actions builder = new Actions(SeleniumUtilities.SearchContextToWebDriver(element)); builder.DoubleClick(element).Build().Perform(); }
/// <summary> /// Drag and drop an element to an X and Y offsets /// </summary> /// <param name="source">Element to drag and drop</param> /// <param name="pixelsXOffset">Integer of pixels to be moved (Positive or negative) horizontally</param> /// <param name="pixelsYOffset">Integer of pixels to be moved (Positive or negative) vertically </param> public static void DragAndDropToOffset(this IWebElement source, int pixelsXOffset, int pixelsYOffset) { Actions builder = new Actions(SeleniumUtilities.SearchContextToWebDriver(source)); builder.DragAndDropToOffset(source, pixelsXOffset, pixelsYOffset).Build().Perform(); }
/// <summary> /// JavaScript method to scroll an element into the view /// </summary> /// <param name="element">IWebElement</param> public static void ScrollIntoView(this IWebElement element) { var driver = SeleniumUtilities.SearchContextToWebDriver(element); driver.ScrollIntoView(element); }