@@ -24,44 +24,44 @@ public ElementFinder(ILocalizedLogger logger, IConditionalWait conditionalWait)
24
24
25
25
private IConditionalWait ConditionalWait { get ; }
26
26
27
- public virtual IWebElement FindElement ( By locator , ElementState state = ElementState . ExistsInAnyState , TimeSpan ? timeout = null )
27
+ public virtual IWebElement FindElement ( By locator , ElementState state = ElementState . ExistsInAnyState , TimeSpan ? timeout = null , string name = null )
28
28
{
29
29
var desiredState = ResolveState ( state ) ;
30
- return FindElement ( locator , desiredState . ElementStateCondition , desiredState . StateName , timeout ) ;
30
+ return FindElement ( locator , desiredState . ElementStateCondition , desiredState . StateName , timeout , name ) ;
31
31
}
32
32
33
- public virtual IWebElement FindElement ( By locator , Func < IWebElement , bool > elementStateCondition , TimeSpan ? timeout = null )
33
+ public virtual IWebElement FindElement ( By locator , Func < IWebElement , bool > elementStateCondition , TimeSpan ? timeout = null , string name = null )
34
34
{
35
- return FindElement ( locator , elementStateCondition , "desired" , timeout ) ;
35
+ return FindElement ( locator , elementStateCondition , "desired" , timeout , name ) ;
36
36
}
37
37
38
- public virtual IWebElement FindElement ( By locator , Func < IWebElement , bool > elementStateCondition , string stateName , TimeSpan ? timeout = null )
38
+ public virtual IWebElement FindElement ( By locator , Func < IWebElement , bool > elementStateCondition , string stateName , TimeSpan ? timeout = null , string name = null )
39
39
{
40
40
var desiredState = new DesiredState ( elementStateCondition , stateName )
41
41
{
42
42
IsCatchingTimeoutException = false ,
43
43
IsThrowingNoSuchElementException = true
44
44
} ;
45
- return FindElements ( locator , desiredState , timeout ) . First ( ) ;
45
+ return FindElements ( locator , desiredState , timeout , name ) . First ( ) ;
46
46
}
47
47
48
- public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , ElementState state = ElementState . ExistsInAnyState , TimeSpan ? timeout = null )
48
+ public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , ElementState state = ElementState . ExistsInAnyState , TimeSpan ? timeout = null , string name = null )
49
49
{
50
50
var elementStateCondition = ResolveState ( state ) ;
51
51
elementStateCondition . IsCatchingTimeoutException = true ;
52
- return FindElements ( locator , elementStateCondition , timeout ) ;
52
+ return FindElements ( locator , elementStateCondition , timeout , name ) ;
53
53
}
54
54
55
- public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , Func < IWebElement , bool > elementStateCondition , TimeSpan ? timeout = null )
55
+ public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , Func < IWebElement , bool > elementStateCondition , TimeSpan ? timeout = null , string name = null )
56
56
{
57
57
var desiredState = new DesiredState ( elementStateCondition , "desired" )
58
58
{
59
- IsCatchingTimeoutException = true
59
+ IsCatchingTimeoutException = true ,
60
60
} ;
61
- return FindElements ( locator , desiredState , timeout ) ;
61
+ return FindElements ( locator , desiredState , timeout , name ) ;
62
62
}
63
63
64
- public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , DesiredState desiredState , TimeSpan ? timeout = null )
64
+ public virtual ReadOnlyCollection < IWebElement > FindElements ( By locator , DesiredState desiredState , TimeSpan ? timeout = null , string name = null )
65
65
{
66
66
var foundElements = new List < IWebElement > ( ) ;
67
67
var resultElements = new List < IWebElement > ( ) ;
@@ -76,14 +76,16 @@ public virtual ReadOnlyCollection<IWebElement> FindElements(By locator, DesiredS
76
76
}
77
77
catch ( WebDriverTimeoutException ex )
78
78
{
79
- HandleTimeoutException ( ex , desiredState , locator , foundElements ) ;
79
+ HandleTimeoutException ( ex , desiredState , locator , foundElements , name ) ;
80
80
}
81
81
return resultElements . AsReadOnly ( ) ;
82
82
}
83
83
84
- protected virtual void HandleTimeoutException ( WebDriverTimeoutException ex , DesiredState desiredState , By locator , List < IWebElement > foundElements )
84
+ protected virtual void HandleTimeoutException ( WebDriverTimeoutException ex , DesiredState desiredState , By locator , List < IWebElement > foundElements , string name = null )
85
85
{
86
- var message = $ "No elements with locator '{ locator . ToString ( ) } ' were found in { desiredState . StateName } state";
86
+ var message = string . IsNullOrEmpty ( name )
87
+ ? $ "No elements with locator '{ locator } ' were found in { desiredState . StateName } state"
88
+ : $ "Element [{ name } ] was not found by locator '{ locator } ' in { desiredState . StateName } state";
87
89
if ( desiredState . IsCatchingTimeoutException )
88
90
{
89
91
if ( ! foundElements . Any ( ) )
@@ -101,12 +103,11 @@ protected virtual void HandleTimeoutException(WebDriverTimeoutException ex, Desi
101
103
}
102
104
else
103
105
{
104
- var combinedMessage = $ "{ ex . Message } : { message } ";
105
106
if ( desiredState . IsThrowingNoSuchElementException && ! foundElements . Any ( ) )
106
107
{
107
- throw new NoSuchElementException ( combinedMessage ) ;
108
+ throw new NoSuchElementException ( $ " { message } : { ex . Message } " ) ;
108
109
}
109
- throw new WebDriverTimeoutException ( combinedMessage ) ;
110
+ throw new WebDriverTimeoutException ( $ " { ex . Message } : { message } " ) ;
110
111
}
111
112
}
112
113
0 commit comments