Skip to content

Commit

Permalink
[dotnet] do not create a new wheel input instance for every scroll me…
Browse files Browse the repository at this point in the history
…thod used
  • Loading branch information
titusfortner committed May 27, 2022
1 parent cb68cf5 commit bf18835
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions dotnet/src/webdriver/Interactions/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -417,8 +418,7 @@ public Actions DragAndDropToOffset(IWebElement source, int offsetX, int offsetY)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
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;
}
Expand All @@ -431,8 +431,7 @@ public Actions ScrollToElement(IWebElement element)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
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;
}
Expand All @@ -452,21 +451,19 @@ public Actions ScrollByAmount(int deltaX, int deltaY)
/// <exception cref="MoveTargetOutOfBoundsException">If the origin with offset is outside the viewport.</exception>
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));
}

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));
}

Expand Down

0 comments on commit bf18835

Please sign in to comment.