我创建了以下代码,它将鼠标按下自动化元素的可点击点,然后将鼠标放在另一个元素的可点击点上。这应该具有拖放的效果,但它不会那样做。它的行为方式很奇怪。似乎只是选择项目而不是拖动。
public static void Main(String[] args)
{
contactsGrid.getCell("Cell Data").drag();
navTree.getNode("Tree Data").drop();
}
public void drag()
{
element.SetFocus();
ScreenClick.leftDown(element);
}
public void drop()
{
element.SetFocus();
ScreenClick.leftUp(element);
}
public static void leftDown(AutomationElement element)
{
while (!element.Current.IsKeyboardFocusable)
element = TreeWalker.RawViewWalker.GetFirstChild(element);
Point p;
element.TryGetClickablePoint(out p);
leftDown((int)p.X, (int)p.Y);
}
public static void leftUp(AutomationElement element)
{
while (!element.Current.IsKeyboardFocusable)
element = TreeWalker.RawViewWalker.GetFirstChild(element);
Point p;
element.TryGetClickablePoint(out p);
leftUp((int)p.X, (int)p.Y);
}
public static void leftDown(int x, int y)
{
Cursor.Position = new System.Drawing.Point(x, y);
mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
}
public static void leftUp(int x, int y)
{
Cursor.Position = new System.Drawing.Point(x, y);
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
}