@@ -26,8 +26,7 @@ namespace OpenQA.Selenium.Interactions
26
26
/// </summary>
27
27
public class Actions : IAction
28
28
{
29
- private readonly TimeSpan DefaultScrollDuration = TimeSpan . FromMilliseconds ( 250 ) ;
30
- private readonly TimeSpan DefaultMouseMoveDuration = TimeSpan . FromMilliseconds ( 250 ) ;
29
+ private readonly TimeSpan duration ;
31
30
private ActionBuilder actionBuilder = new ActionBuilder ( ) ;
32
31
private PointerInputDevice activePointer ;
33
32
private KeyInputDevice activeKeyboard ;
@@ -39,6 +38,17 @@ public class Actions : IAction
39
38
/// </summary>
40
39
/// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
41
40
public Actions ( IWebDriver driver )
41
+ : this ( driver , TimeSpan . FromMilliseconds ( 250 ) )
42
+ {
43
+
44
+ }
45
+
46
+ /// <summary>
47
+ /// Initializes a new instance of the <see cref="Actions"/> class.
48
+ /// </summary>
49
+ /// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
50
+ /// <param name="duration">How long durable action is expected to take.</param>
51
+ public Actions ( IWebDriver driver , TimeSpan duration )
42
52
{
43
53
IActionExecutor actionExecutor = GetDriverAs < IActionExecutor > ( driver ) ;
44
54
if ( actionExecutor == null )
@@ -47,6 +57,8 @@ public Actions(IWebDriver driver)
47
57
}
48
58
49
59
this . actionExecutor = actionExecutor ;
60
+
61
+ this . duration = duration ;
50
62
}
51
63
52
64
/// <summary>
@@ -242,7 +254,7 @@ public Actions KeyDown(IWebElement element, string theKey)
242
254
ILocatable target = GetLocatableFromElement ( element ) ;
243
255
if ( element != null )
244
256
{
245
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , DefaultMouseMoveDuration ) ) ;
257
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , duration ) ) ;
246
258
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerDown ( MouseButton . Left ) ) ;
247
259
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerUp ( MouseButton . Left ) ) ;
248
260
}
@@ -286,7 +298,7 @@ public Actions KeyUp(IWebElement element, string theKey)
286
298
ILocatable target = GetLocatableFromElement ( element ) ;
287
299
if ( element != null )
288
300
{
289
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , DefaultMouseMoveDuration ) ) ;
301
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , duration ) ) ;
290
302
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerDown ( MouseButton . Left ) ) ;
291
303
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerUp ( MouseButton . Left ) ) ;
292
304
}
@@ -321,7 +333,7 @@ public Actions SendKeys(IWebElement element, string keysToSend)
321
333
ILocatable target = GetLocatableFromElement ( element ) ;
322
334
if ( element != null )
323
335
{
324
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , DefaultMouseMoveDuration ) ) ;
336
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( element , 0 , 0 , duration ) ) ;
325
337
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerDown ( MouseButton . Left ) ) ;
326
338
this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerUp ( MouseButton . Left ) ) ;
327
339
}
@@ -448,7 +460,7 @@ public Actions MoveToElement(IWebElement toElement)
448
460
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
449
461
public Actions MoveToElement ( IWebElement toElement , int offsetX , int offsetY )
450
462
{
451
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( toElement , offsetX , offsetY , DefaultMouseMoveDuration ) ) ;
463
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( toElement , offsetX , offsetY , duration ) ) ;
452
464
return this ;
453
465
}
454
466
@@ -460,7 +472,7 @@ public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY)
460
472
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
461
473
public Actions MoveByOffset ( int offsetX , int offsetY )
462
474
{
463
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( CoordinateOrigin . Pointer , offsetX , offsetY , DefaultMouseMoveDuration ) ) ;
475
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( CoordinateOrigin . Pointer , offsetX , offsetY , duration ) ) ;
464
476
return this ;
465
477
}
466
478
@@ -472,7 +484,7 @@ public Actions MoveByOffset(int offsetX, int offsetY)
472
484
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
473
485
public Actions MoveToLocation ( int offsetX , int offsetY )
474
486
{
475
- this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( CoordinateOrigin . Viewport , offsetX , offsetY , DefaultMouseMoveDuration ) ) ;
487
+ this . actionBuilder . AddAction ( this . GetActivePointer ( ) . CreatePointerMove ( CoordinateOrigin . Viewport , offsetX , offsetY , duration ) ) ;
476
488
return this ;
477
489
}
478
490
@@ -530,7 +542,7 @@ public Actions DragAndDropToOffset(IWebElement source, int offsetX, int offsetY)
530
542
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
531
543
public Actions ScrollToElement ( IWebElement element )
532
544
{
533
- this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( element , 0 , 0 , 0 , 0 , DefaultScrollDuration ) ) ;
545
+ this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( element , 0 , 0 , 0 , 0 , duration ) ) ;
534
546
535
547
return this ;
536
548
}
@@ -543,7 +555,7 @@ public Actions ScrollToElement(IWebElement element)
543
555
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
544
556
public Actions ScrollByAmount ( int deltaX , int deltaY )
545
557
{
546
- this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( deltaX , deltaY , DefaultScrollDuration ) ) ;
558
+ this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( deltaX , deltaY , duration ) ) ;
547
559
548
560
return this ;
549
561
}
@@ -571,12 +583,12 @@ public Actions ScrollFromOrigin(WheelInputDevice.ScrollOrigin scrollOrigin, int
571
583
if ( scrollOrigin . Viewport )
572
584
{
573
585
this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( CoordinateOrigin . Viewport ,
574
- scrollOrigin . XOffset , scrollOrigin . YOffset , deltaX , deltaY , DefaultScrollDuration ) ) ;
586
+ scrollOrigin . XOffset , scrollOrigin . YOffset , deltaX , deltaY , duration ) ) ;
575
587
}
576
588
else
577
589
{
578
590
this . actionBuilder . AddAction ( this . GetActiveWheel ( ) . CreateWheelScroll ( scrollOrigin . Element ,
579
- scrollOrigin . XOffset , scrollOrigin . YOffset , deltaX , deltaY , DefaultScrollDuration ) ) ;
591
+ scrollOrigin . XOffset , scrollOrigin . YOffset , deltaX , deltaY , duration ) ) ;
580
592
}
581
593
582
594
return this ;
0 commit comments