Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

How to Drag and Drop the AutomationElement using patterns or by Mouse Operation

$
0
0

Hi,

I want to implement an Automation tool, which will automate the test using UI.

I am implementing it using WPF,C# and using AutomationElement I have implemented the Pattern for the controls.

I am stuck at "How to Drag and Drop a AutomationElement object" using pattern or by using Mouse operation.

Here I do not want to access Coded UI Drag and Drop mechanism.

1) Please provide me some guidlines so that I can get some idea.

2) I have implemented following class for Drag and Drop.

The problem I am facing is that I am able to drag the element but the drop is too fast, so that 

MouseDown cannot hold the object and only move the cursur.

Please take a look at the following code,

using System;using System.Runtime.InteropServices;using System.Threading;namespace TestRunEngine.Controls.Control
{    public class MouseOperations    {               [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]        public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo);        private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;        private const uint MOUSEEVENTF_LEFTUP = 0x0004;        private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;        private const uint MOUSEEVENTF_RIGHTUP = 0x0010;        private const uint MOUSEEVENTF_ABSOLUTE = 0x8000;        private const uint MOUSEEVENTF_MOVE = 0x0001;        [DllImport("user32.dll", CharSet = CharSet.Unicode)]        static extern bool SetCursorPos(uint x, uint y);        public static void PerformClick(uint x, uint y)        {            SetCursorPos(x, y);            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, x, y, 0, UIntPtr.Zero);            Thread.Sleep(100);            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, x, y, 0, UIntPtr.Zero);        }        public static void PerformRightClick(uint x, uint y)        {            SetCursorPos(x, y);            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTDOWN, x, y, 0, UIntPtr.Zero);            Thread.Sleep(100);            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTUP, x, y, 0, UIntPtr.Zero);        }        public static void PerformDoubleClick(uint x, uint y)        {            PerformClick(x, y);            Thread.Sleep(250);            PerformClick(x, y);        }        public static void PerformDrag(uint x, uint y)        {            SetCursorPos(x, y);             mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN , x, y, 0, UIntPtr.Zero);            Thread.Sleep(1000);        }                public static void PerformDrop(uint x, uint y)        {               Thread.Sleep(250);                mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, UIntPtr.Zero);            SetCursorPos(x, y);            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, x, y, 0, UIntPtr.Zero);                   }    }
}

Thanks & Regards,

Rosy D.



Viewing all articles
Browse latest Browse all 585

Trending Articles