首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Winapp驱动程序对UI元素进行拖放

使用Winapp驱动程序对UI元素进行拖放
EN

Stack Overflow用户
提问于 2019-11-18 13:38:28
回答 2查看 721关注 0票数 0

我在visual studio中安装了一个插件,它允许我创建一个窗体UI。现在,我正在尝试使用winapp驱动程序在自动化脚本的帮助下将元素拖放到表单屏幕上,但我无法做到这一点。

代码语言:javascript
复制
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中的一个示例尝试了这段代码,但没有成功。

EN

回答 2

Stack Overflow用户

发布于 2019-12-17 00:20:59

使用MouseKeyboard已经过时了。您应该将Appium更新到最新版本,并使用OpenQA.Selenium.Interactions.Actions

代码语言:javascript
复制
/// <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;
  }
}
票数 0
EN

Stack Overflow用户

发布于 2021-04-12 00:36:05

如果您需要使用IWebElement,您可以使用next DragAndDrop extension或新的offset:

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58908552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档