我创建了以下代码,它将鼠标悬停在自动元素的可点击点上,然后鼠标悬停在另一个元素的可单击点上。这应该具有拖放的效果,但它没有这样做。它的行为很奇怪。它似乎只是选择项目而不是拖动。
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);
}