我试图用Selenium示例在这个站点上实现简单的拖放操作:https://demoqa.com/droppable。它的外观:

而且,我使用Atata实现的拖放似乎不起作用。我没有错误,但实际上什么都没有发生。
我的实施:
页对象:
{
using _ = DemoQAInteractionsPage;
[Url("interaction")]
[WaitForDocumentReadyState]
public class DemoQAInteractionsPage : Page<_>
{
[FindById("item-3")]
[ScrollsUsingScript]
public Control<_> DroppableMenu { get; private set; }
[FindById]
[DragsAndDropsUsingActions]
[WaitUntilEnabled]
public Control<_> Draggable { get; private set; }
[FindById]
[DragsAndDropsUsingActions]
[WaitUntilEnabled]
public Control<_> Droppable { get; private set; }
[FindByContent("Dropped!")]
[WaitUntilEnabled]
public Control<_> DroppedMessage { get; private set; }
}
}测试:
[Test]
public void DemoQADragAndDropTest()
{
Go.To<DemoQAMainPage>()
.GoToInteractions();
Go.To<DemoQAInteractionsPage>(navigate: false)
.DroppableMenu.ScrollTo()
.DroppableMenu.Click()
.Draggable.DragAndDropTo(x => x.Droppable);
}我知道普通的Selenium实现,但更喜欢Atata。你能提点建议吗?
更新:由于某种原因,这种方法是有效的:
public _ PerformDragAndDrop()
{
IWebElement target = Droppable.GetScope();
IWebElement source = Draggable.GetScope();
Actions actions = new Actions(Driver);
actions.ClickAndHold(source);
actions.MoveToElement(target);
actions.Perform();
actions.Release(target);
actions.Perform();
return this;
}我读过关于这个问题的,也许,它是与显色剂有关的。无论如何,这可以作为一种解决办法,使用Atata仍然更好。也许,在显色剂中有一些与这个问题有关的众所周知的错误?
发布于 2022-02-18 10:35:38
尽管测试对我有用,但您可以创建拖放行为类:
public class DragsAndDropsUsingActionsStepByStepAttribute : DragAndDropBehaviorAttribute
{
public override void Execute<TOwner>(IControl<TOwner> component, IControl<TOwner> target)
{
IWebElement sourceElement = component.Scope;
IWebElement targetElement = component.Scope;
Actions actions = new Actions(component.Context.Driver);
actions.ClickAndHold(sourceElement);
actions.MoveToElement(targetElement);
actions.Perform();
actions.Release(targetElement);
actions.Perform();
}
}并将其应用于Draggable属性:
[FindById]
[DragsAndDropsUsingActionsStepByStep]
public Control<_> Draggable { get; private set; }https://stackoverflow.com/questions/71166350
复制相似问题