/// <summary> /// Moves the mouse to the element and offset specified. /// </summary> /// <returns>This command always returns <see langword="null"/>.</returns> public override object Execute() { IHasInputDevices hasInputDevicesDriver = this.Session.Driver as IHasInputDevices; IMouse mouse = hasInputDevicesDriver.Mouse; ICoordinates elementLocation = null; if (this.elementProvided) { IWebElement element = this.Session.KnownElements.GetElement(this.elementId); ILocatable locatableElement = element as ILocatable; elementLocation = locatableElement.Coordinates; } if (this.offsetsProvided) { mouse.MouseMove(elementLocation, this.offsetX, this.offsetY); } else { mouse.MouseMove(elementLocation); } mouse.MouseDown(null); return(null); }
public void MouseMove(ICoordinates where) { var MRes = new ManualResetEventSlim(true); MRes.Reset(); Exception exception = null; Task.Run(async() => { try { await mouse.MouseMove(where).ConfigureAwait(false); } catch (Exception ex) { exception = ex; } MRes.Set(); } ); MRes.Wait(); if (exception != null) { throw exception; } }
public void MouseMove(ICoordinates where) { Location location = Location_(where); Logger.Verbose("MouseMove(" + location + ")"); if (location != null) { mouseLocation_ = new Location(Math.Max(0, location.X), Math.Max(0, location.Y)); AddMouseTrigger_(MouseAction.Move); } mouse_.MouseMove(where); }
public override bool MouseMove(string frameId, string xpathExpression, string scenarioName, int stepNumber) { try { if (frameId != null) { driver.SwitchTo().Frame(frameId); } ILocatable locatableItem = (ILocatable)this.driver.FindElement(By.XPath(xpathExpression)); IMouse mouse = ((IHasInputDevices)this.driver).Mouse; mouse.MouseMove(locatableItem.Coordinates); driver.SwitchTo().DefaultContent(); Direct(scenarioName, stepNumber, 0, null); return(true); } catch (Exception ex) { driver.SwitchTo().DefaultContent(); Console.WriteLine("ClearTextField Error: " + ex.ToString()); Direct(scenarioName, stepNumber, error, ex.ToString()); return(false); } }
public static void MouseHoverUsingIWebElement(this IWebDriver driver, IWebElement element) { ILocatable hoverItem = (ILocatable)element; IMouse mouse = ((IHasInputDevices)element).Mouse; mouse.MouseMove(hoverItem.Coordinates); }
/// <summary> /// mouse hover using Element /// </summary> /// <param name="driver"></param> /// <param name="When"></param> /// <param name="How"></param> public static void MouseHoverUsingElement(this IWebDriver driver, string When, string How) { ILocatable hoverItem = (ILocatable)driver._findElement(When, How); IMouse mouse = ((IHasInputDevices)driver).Mouse; mouse.MouseMove(hoverItem.Coordinates); }
/// <summary> /// Performs a MouseMove event on the specified element via ILocatable interface. /// </summary> /// <param name="elementName">Element to operate on.</param> public void MouseMove(IWebElement element) { WaitForElementToBePresent(element); ILocatable locatable = (ILocatable)element; mouse.MouseMove(locatable.Coordinates); }
/// <summary> /// mouse hover on the element /// </summary> /// <param name="driver"></param> /// <param name="When"></param> /// <param name="How"></param> public static void _mouseOver(this IWebDriver driver, string When, string How, string When1, string How1) { IWebElement element = driver._findElement(When, How); ILocatable hoverItem = (ILocatable)element; IMouse mouse = ((IHasInputDevices)driver).Mouse; mouse.MouseMove(hoverItem.Coordinates); //logger.debug("Hover on 'Action' and click '); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); wait.Until(x => x._findElement(When1, How1)); driver._findElement(When1, How1).Click(); }
/// <summary> /// Drag over this widget to another widget /// </summary> /// <param name="target">The target widget.</param> public virtual void DragOver(IWidget target) { IMouse mouse = ((IHasInputDevices)Driver.WebDriver).Mouse; ILocatable root = (ILocatable)Driver.FindElement(By.TagName("body")); //cast IWebElement to ILocatable ILocatable sourceL = (ILocatable)_contentElement; ILocatable targetL = (ILocatable)target.ContentElement; ICoordinates coord = root.Coordinates; mouse.MouseDown(sourceL.Coordinates); //get source position (center,center) int sourceX = sourceL.Coordinates.LocationInDom.X + _contentElement.Size.Width / 2; int sourceY = sourceL.Coordinates.LocationInDom.Y + _contentElement.Size.Height / 2; // get target position (center, center) int targetX = targetL.Coordinates.LocationInDom.X + target.ContentElement.Size.Width / 2; int targetY = targetL.Coordinates.LocationInDom.Y + target.ContentElement.Size.Height / 2; //compute deltas between source and target position //delta must be positive, however //also we have to define the direction int directionX = 1; //move direction is right int directionY = 1; //move direction is bottom var deltaX = targetX - sourceX; if (deltaX < 0) { deltaX *= -1; directionX = -1; // move direction is left } var deltaY = targetY - sourceY; if (deltaY < 0) { deltaY *= -1; directionY = -1; // move direction is top } //define base delta, which must be the higher one int baseDelta = deltaX; if (deltaY > deltaX) { baseDelta = deltaY; } // iterate base delta, set mouse cursor in relation to delta x & delta y int x = 0; int y = 0; for (int i = 1; i <= baseDelta; i += 4) { if (i > baseDelta) { i = baseDelta; } x = sourceX + deltaX * i / baseDelta * directionX; y = sourceY + deltaY * i / baseDelta * directionY; mouse.MouseMove(coord, x, y); //System.out.println(x +", "+ y); Thread.Sleep(1); } // source has the same coordinates as target if (sourceX == targetX && sourceY == targetY) { mouse.MouseMove(targetL.Coordinates, x++, y); Thread.Sleep(20); } }
/// <summary> /// Performs a MouseMove event on the specified element via ILocatable interface. /// </summary> /// <param name="elementName">Element to operate on.</param> public void MouseMove(IWebElement element) { ILocatable locatable = (ILocatable)element; mouse.MouseMove(locatable.Coordinates); }