diff --git a/dotnet/src/webdriver/Interactions/Actions.cs b/dotnet/src/webdriver/Interactions/Actions.cs index 00c8ecb188860..a6946b712f337 100644 --- a/dotnet/src/webdriver/Interactions/Actions.cs +++ b/dotnet/src/webdriver/Interactions/Actions.cs @@ -52,6 +52,7 @@ public class Actions : IAction private ActionBuilder actionBuilder = new ActionBuilder(); private PointerInputDevice defaultMouse = new PointerInputDevice(PointerKind.Mouse, "default mouse"); private KeyInputDevice defaultKeyboard = new KeyInputDevice("default keyboard"); + private WheelInputDevice defaultWheel = new WheelInputDevice("default wheel"); private IActionExecutor actionExecutor; /// @@ -417,8 +418,7 @@ public Actions DragAndDropToOffset(IWebElement source, int offsetX, int offsetY) /// A self-reference to this . public Actions ScrollToElement(IWebElement element) { - WheelInputDevice wheel = new WheelInputDevice(); - this.actionBuilder.AddAction(wheel.CreateWheelScroll(element, 0, 0, 0, 0, DefaultScrollDuration)); + this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(element, 0, 0, 0, 0, DefaultScrollDuration)); return this; } @@ -431,8 +431,7 @@ public Actions ScrollToElement(IWebElement element) /// A self-reference to this . public Actions ScrollByAmount(int deltaX, int deltaY) { - WheelInputDevice wheel = new WheelInputDevice(); - this.actionBuilder.AddAction(wheel.CreateWheelScroll(deltaX, deltaY, DefaultScrollDuration)); + this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(deltaX, deltaY, DefaultScrollDuration)); return this; } @@ -452,8 +451,6 @@ public Actions ScrollByAmount(int deltaX, int deltaY) /// If the origin with offset is outside the viewport. public Actions ScrollFromOrigin(WheelInputDevice.ScrollOrigin scrollOrigin, int deltaX, int deltaY) { - WheelInputDevice wheel = new WheelInputDevice(); - if (scrollOrigin.Viewport && scrollOrigin.Element != null) { throw new ArgumentException("viewport can not be true if an element is defined.", nameof(scrollOrigin)); @@ -461,12 +458,12 @@ public Actions ScrollFromOrigin(WheelInputDevice.ScrollOrigin scrollOrigin, int if (scrollOrigin.Viewport) { - this.actionBuilder.AddAction(wheel.CreateWheelScroll(CoordinateOrigin.Viewport, + this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(CoordinateOrigin.Viewport, scrollOrigin.XOffset, scrollOrigin.YOffset, deltaX, deltaY, DefaultScrollDuration)); } else { - this.actionBuilder.AddAction(wheel.CreateWheelScroll(scrollOrigin.Element, + this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(scrollOrigin.Element, scrollOrigin.XOffset, scrollOrigin.YOffset, deltaX, deltaY, DefaultScrollDuration)); }