@@ -29,49 +29,50 @@ public static Task ClickReliablyAsync(this IWebElement element, UITestContext co
29
29
element ,
30
30
async ( ) =>
31
31
{
32
- try
33
- {
34
- await context . Configuration . Events . BeforeClick
35
- . InvokeAsync < ClickEventHandler > ( eventHandler => eventHandler ( context , element ) ) ;
32
+ await context . Configuration . Events . BeforeClick
33
+ . InvokeAsync < ClickEventHandler > ( eventHandler => eventHandler ( context , element ) ) ;
36
34
37
- // When the button is under some overhanging UI element, the MoveToElement sometimes fails with the
38
- // "move target out of bounds" exception message. And while the UI is changing, wrongly timed clicks
39
- // can fail with StaleElementReferenceExceptions.
40
- // In these cases it should be retried.
41
- var notFound = true ;
42
- for ( var i = 1 ; notFound && i <= maxTries ; i ++ )
35
+ // When the button is under some overhanging UI element, the MoveToElement sometimes fails with the
36
+ // "move target out of bounds" exception message. And while the UI is changing, wrongly timed clicks can
37
+ // fail with StaleElementReferenceExceptions. In these cases it should be retried.
38
+ var notFound = true ;
39
+ for ( var i = 1 ; notFound && i <= maxTries ; i ++ )
40
+ {
41
+ try
43
42
{
44
- try
45
- {
46
- context . Driver . Perform ( actions => actions . MoveToElement ( element ) . Click ( ) ) ;
47
- notFound = false ;
48
- }
49
- catch ( WebDriverException ex ) when ( i < maxTries && ex . Message . Contains ( "move target out of bounds" ) )
43
+ context . Driver . Perform ( actions => actions . MoveToElement ( element ) . Click ( ) ) ;
44
+ notFound = false ;
45
+ }
46
+ catch ( WebDriverException ex ) when ( i < maxTries )
47
+ {
48
+ switch ( ex . Message )
50
49
{
51
- context . Configuration . TestOutputHelper . WriteLineTimestampedAndDebug (
52
- "\" move target out of bounds\" exception, retrying the click." ) ;
50
+ case string message when message . Contains ( "move target out of bounds" ) :
51
+ context . Configuration . TestOutputHelper . WriteLineTimestampedAndDebug (
52
+ "\" move target out of bounds\" exception, retrying the click." ) ;
53
+ break ;
53
54
54
- await Task . Delay ( RetrySettings . Interval , context . Configuration . TestCancellationToken ) ;
55
- }
56
- catch ( StaleElementReferenceException ) when ( i < maxTries )
57
- {
58
- context . Configuration . TestOutputHelper . WriteLineTimestampedAndDebug (
59
- "Stale element reference exception, retrying the click." ) ;
55
+ case string message when ex . IsStateElementLikeException ( ) :
56
+ context . Configuration . TestOutputHelper . WriteLineTimestampedAndDebug (
57
+ "Stale element exception with the message \" {0}\" , retrying the click." ,
58
+ message ) ;
59
+ break ;
60
+
61
+ case string message when message . ContainsOrdinalIgnoreCase (
62
+ "javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite." ) :
63
+ throw new NotSupportedException (
64
+ "For this element use the standard Click() method." ) ;
60
65
61
- await Task . Delay ( RetrySettings . Interval , context . Configuration . TestCancellationToken ) ;
66
+ default :
67
+ throw ;
62
68
}
63
- }
64
69
65
- await context . Configuration . Events . AfterClick
66
- . InvokeAsync < ClickEventHandler > ( eventHandler => eventHandler ( context , element ) ) ;
67
- }
68
- catch ( WebDriverException ex )
69
- when ( ex . Message . ContainsOrdinalIgnoreCase (
70
- "javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite." ) )
71
- {
72
- throw new NotSupportedException (
73
- "For this element use the standard Click() method." ) ;
70
+ await Task . Delay ( RetrySettings . Interval , context . Configuration . TestCancellationToken ) ;
71
+ }
74
72
}
73
+
74
+ await context . Configuration . Events . AfterClick
75
+ . InvokeAsync < ClickEventHandler > ( eventHandler => eventHandler ( context , element ) ) ;
75
76
} ) ;
76
77
77
78
/// <inheritdoc cref="ClickReliablyUntilNavigationHasOccurredAsync(IWebElement, UITestContext, TimeSpan?, TimeSpan?)"/>
@@ -122,7 +123,7 @@ public static Task ClickReliablyUntilUrlChangeAsync(
122
123
{
123
124
await element . ClickReliablyAsync ( context ) ;
124
125
}
125
- catch ( StaleElementReferenceException )
126
+ catch ( WebDriverException ex ) when ( ex . IsStateElementLikeException ( ) )
126
127
{
127
128
// If navigation happened while retrying the click, the element will become stale, but that's normal.
128
129
}
0 commit comments