Skip to content

Commit bf18835

Browse files
committed
[dotnet] do not create a new wheel input instance for every scroll method used
1 parent cb68cf5 commit bf18835

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

‎dotnet/src/webdriver/Interactions/Actions.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class Actions : IAction
5252
private ActionBuilder actionBuilder = new ActionBuilder();
5353
private PointerInputDevice defaultMouse = new PointerInputDevice(PointerKind.Mouse, "default mouse");
5454
private KeyInputDevice defaultKeyboard = new KeyInputDevice("default keyboard");
55+
private WheelInputDevice defaultWheel = new WheelInputDevice("default wheel");
5556
private IActionExecutor actionExecutor;
5657

5758
/// <summary>
@@ -417,8 +418,7 @@ public Actions DragAndDropToOffset(IWebElement source, int offsetX, int offsetY)
417418
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
418419
public Actions ScrollToElement(IWebElement element)
419420
{
420-
WheelInputDevice wheel = new WheelInputDevice();
421-
this.actionBuilder.AddAction(wheel.CreateWheelScroll(element, 0, 0, 0, 0, DefaultScrollDuration));
421+
this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(element, 0, 0, 0, 0, DefaultScrollDuration));
422422

423423
return this;
424424
}
@@ -431,8 +431,7 @@ public Actions ScrollToElement(IWebElement element)
431431
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
432432
public Actions ScrollByAmount(int deltaX, int deltaY)
433433
{
434-
WheelInputDevice wheel = new WheelInputDevice();
435-
this.actionBuilder.AddAction(wheel.CreateWheelScroll(deltaX, deltaY, DefaultScrollDuration));
434+
this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(deltaX, deltaY, DefaultScrollDuration));
436435

437436
return this;
438437
}
@@ -452,21 +451,19 @@ public Actions ScrollByAmount(int deltaX, int deltaY)
452451
/// <exception cref="MoveTargetOutOfBoundsException">If the origin with offset is outside the viewport.</exception>
453452
public Actions ScrollFromOrigin(WheelInputDevice.ScrollOrigin scrollOrigin, int deltaX, int deltaY)
454453
{
455-
WheelInputDevice wheel = new WheelInputDevice();
456-
457454
if (scrollOrigin.Viewport && scrollOrigin.Element != null)
458455
{
459456
throw new ArgumentException("viewport can not be true if an element is defined.", nameof(scrollOrigin));
460457
}
461458

462459
if (scrollOrigin.Viewport)
463460
{
464-
this.actionBuilder.AddAction(wheel.CreateWheelScroll(CoordinateOrigin.Viewport,
461+
this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(CoordinateOrigin.Viewport,
465462
scrollOrigin.XOffset, scrollOrigin.YOffset, deltaX, deltaY, DefaultScrollDuration));
466463
}
467464
else
468465
{
469-
this.actionBuilder.AddAction(wheel.CreateWheelScroll(scrollOrigin.Element,
466+
this.actionBuilder.AddAction(this.defaultWheel.CreateWheelScroll(scrollOrigin.Element,
470467
scrollOrigin.XOffset, scrollOrigin.YOffset, deltaX, deltaY, DefaultScrollDuration));
471468
}
472469

0 commit comments

Comments
 (0)