public void MouseDown(ICoordinates where)
        {
            var MRes = new ManualResetEventSlim(true);

            MRes.Reset();
            Exception exception = null;

            Task.Run(async() =>
            {
                try
                {
                    await mouse.MouseDown(where).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                MRes.Set();
            }

                     );
            MRes.Wait();
            if (exception != null)
            {
                throw exception;
            }
        }
        /// <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);
        }
Beispiel #3
0
 /// <summary>
 /// Performs a long tap on the element of the specified driver.
 /// </summary>
 /// <param name="driver">The driver to use.</param>
 /// <param name="element">The element to long tap.</param>
 public static void Longtap(IWebDriver driver, IWebElement element)
 {
     if (driver is IHasTouchScreen)
     {
         TouchActions longtap = new TouchActions(driver);
         Point        center  = GetCenter(element);
         longtap.Down(center.X, center.Y);
         longtap.Perform();
         try
         {
             Thread.Sleep(750);
         }
         catch (ThreadInterruptedException)
         {
         }
         longtap.Up(center.X, center.Y);
         longtap.Perform();
     }
     else
     {
         ILocatable   locatable = (ILocatable)element;
         ICoordinates coords    = locatable.Coordinates;
         IMouse       mouse     = ((IHasInputDevices)driver).Mouse;
         mouse.MouseDown(coords);
         try
         {
             Thread.Sleep(750);
         }
         catch (ThreadInterruptedException)
         {
         }
         mouse.MouseUp(coords);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Performs a MouseDown event on the specified element via ILocatable interface.
        /// </summary>
        /// <param name="elementName">Element to operate on.</param>
        public void MouseDown(IWebElement element)
        {
            WaitForElementToBePresent(element);
            ILocatable locatable = (ILocatable)element;

            mouse.MouseDown(locatable.Coordinates);
        }
Beispiel #5
0
        /// <summary>
        /// Presses the left mouse button at the last coordinates set for the driver.
        /// </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;

            mouse.MouseDown(null);
            return(null);
        }
Beispiel #6
0
        public void MouseDown(ICoordinates where)
        {
            Location location = Location_(where);

            Logger.Verbose("MouseDown({0})", location);

            MoveIfNeeded(where);
            AddMouseTrigger_(MouseAction.Down);

            Logger.Verbose("MouseDown(): Location is {0}", mouseLocation_);
            mouse_.MouseDown(where);
        }
Beispiel #7
0
        /// <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);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Performs a MouseDown event on the specified element via ILocatable interface.
        /// </summary>
        /// <param name="elementName">Element to operate on.</param>
        public void MouseDown(IWebElement element)
        {
            ILocatable locatable = (ILocatable)element;

            mouse.MouseDown(locatable.Coordinates);
        }