【问题标题】:How drag and drop will be perfomed in the Winapp driver.?Winappdriver中将如何进行拖放。
【发布时间】:2020-12-11 00:00:47
【问题描述】:

我正在使用 Outlook,我需要将一封电子邮件拖放到第二个文件夹中。

我厌倦了下面的代码:

Actions builder = new Actions(driver);
builder.ClickAndHold(from).MoveToElement(to).Release().Build().Perform();
Or
builder.DragAndDrop(from, to).MoveToElement(to).Build().Perform();

这样我可以执行单击并按住鼠标操作,但电子邮件不会被移动到第二个文件夹中。

【问题讨论】:

    标签: c# visual-studio-2019 winappdriver


    【解决方案1】:

    下一个 IWebElement DragAndDrop extension 为我工作:

    public static void DragAndDrop(this IWebElement source, IWebElement destination)
    {
        var destinationCenterX = destination.Location.X + destination.Size.Width / 2;
        var destinationCenterY = destination.Location.Y + destination.Size.Height / 2;
        var action = new Actions(source.GetDriver());
        action.MoveToElement(source).Build().Perform();
        action.ClickAndHold(source).MoveByOffset(destinationCenterX, destinationCenterY).Build().Perform();
        destination.Click();
        action.Release().Perform();
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 2020-03-09
      • 2010-11-22
      • 1970-01-01
      • 2019-11-06
      • 2022-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多