c# - Winapp 驱动程序中如何进行拖放。
问题描述
我正在使用 Outlook,我需要将一封电子邮件拖放到第二个文件夹中。
我厌倦了下面的代码:
Actions builder = new Actions(driver);
builder.ClickAndHold(from).MoveToElement(to).Release().Build().Perform();
Or
builder.DragAndDrop(from, to).MoveToElement(to).Build().Perform();
有了这个,我可以执行单击并按住鼠标操作,但电子邮件不会被移动到第二个文件夹中。
解决方案
下一个为我工作的 IWebElement DragAndDrop扩展:
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();
}
推荐阅读
- python - 如何循环一个turtle.write 语句?
- python-3.x - 字典值未更新
- python - 使用 Python 代码求解简单的 sigma-Algebra(概率中也称为 Borel 场)
- c - 在 C 中的方法名称上有一个星号是什么意思?
- c++ - For循环:打印结果最高的汽车名称。如果相等,取第一个
- swift - 我不能在点后显示两位数,例如 0.3、0.4
- c++ - 在单独的 txt 文件中验证用户名和密码
- django - Django Inline 下载未在浏览器中正确显示文件名
- r - 当像素并不总是对齐时,在谷歌地球引擎或 rgee 中添加多个图像?
- python - 使用 Django 构建复杂的动态查询