0

我在 Visual Studio 中安装了一个插件,可让我创建表单 UI。现在,我正在尝试借助使用 winapp 驱动程序的自动化脚本在表单屏幕上拖放一个元素,但我无法做到这一点。

var FindVSProjectWindow = DesktopSession.FindElementByName("SystemModeler4 - Microsoft Visual Studio  (Administrator)");
            if (FindVSProjectWindow != null)
            {
                const int offset = 100;

                var FindAttribute = DesktopSession.FindElementByName("VsClassViewMembersPane").FindElementByName("Attribute1");

                DesktopSession.Mouse.MouseMove(FindAttribute.Coordinates);
                DesktopSession.Mouse.MouseDown(null); // Pass null as this command omit the given parameter
                DesktopSession.Mouse.MouseMove(FindAttribute.Coordinates, offset, offset);
                DesktopSession.Mouse.MouseUp(null); // Pass null as this command omit the given parameter
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

我使用来自 github 的示例尝试了此代码,但没有发生。

4

2 回答 2

0

使用MouseandKeyboard已过时。您应该将 Appium 更新到最新版本并OpenQA.Selenium.Interactions.Actions改用。

/// <summary>
/// Gets an <see cref="T:OpenQA.Selenium.IMouse" /> object for sending mouse commands to the browser.
/// </summary>
[Obsolete("This property was never intended to be used in user code. Use the Actions or ActionBuilder class to send direct mouse input.")]
public IMouse Mouse
{
  get
  {
    return this.mouse;
  }
}

/// <summary>
/// Gets an <see cref="T:OpenQA.Selenium.IKeyboard" /> object for sending keystrokes to the browser.
/// </summary>
[Obsolete("This property was never intended to be used in user code. Use the Actions or ActionBuilder class to send direct keyboard input.")]
public IKeyboard Keyboard
{
  get
  {
    return this.keyboard;
  }
}
于 2019-12-16T16:20:58.717 回答
0

如果需要使用偏移量,可以使用下一个 IWebElement DragAndDrop扩展或新扩展:

public void DragAndDropWithOffset(this IWebElement source, IWebElement destination, Point destinationOffset)
{
    var destinationCenterX = destination.Location.X + point.X;
    var destinationCenterY = destination.Location.Y + point.Y;
    var action = new Actions(source.GetDriver());
    action.MoveToElement(source).Build().Perform();
    action.ClickAndHold(source).MoveByOffset(destinationCenterX, destinationCenterY).Build().Perform();
    destination.Click();
    action.Release().Perform();
}
于 2021-04-11T16:36:05.433 回答