我在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中的一个示例尝试了这段代码,但没有成功。
发布于 2019-12-17 00:20:59
使用Mouse和Keyboard已经过时了。您应该将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;
}
}发布于 2021-04-12 00:36:05
如果您需要使用IWebElement,您可以使用next DragAndDrop extension或新的offset:
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();
}https://stackoverflow.com/questions/58908552
复制相似问题