@@ -24,44 +24,44 @@ public ElementFinder(ILocalizedLogger logger, IConditionalWait conditionalWait)
2424
2525 private IConditionalWait ConditionalWait { get ; }
2626
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 )
2828 {
2929 var desiredState = ResolveState ( state ) ;
30- return FindElement ( locator , desiredState . ElementStateCondition , desiredState . StateName , timeout ) ;
30+ return FindElement ( locator , desiredState . ElementStateCondition , desiredState . StateName , timeout , name ) ;
3131 }
3232
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 )
3434 {
35- return FindElement ( locator , elementStateCondition , "desired" , timeout ) ;
35+ return FindElement ( locator , elementStateCondition , "desired" , timeout , name ) ;
3636 }
3737
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 )
3939 {
4040 var desiredState = new DesiredState ( elementStateCondition , stateName )
4141 {
4242 IsCatchingTimeoutException = false ,
4343 IsThrowingNoSuchElementException = true
4444 } ;
45- return FindElements ( locator , desiredState , timeout ) . First ( ) ;
45+ return FindElements ( locator , desiredState , timeout , name ) . First ( ) ;
4646 }
4747
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 )
4949 {
5050 var elementStateCondition = ResolveState ( state ) ;
5151 elementStateCondition . IsCatchingTimeoutException = true ;
52- return FindElements ( locator , elementStateCondition , timeout ) ;
52+ return FindElements ( locator , elementStateCondition , timeout , name ) ;
5353 }
5454
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 )
5656 {
5757 var desiredState = new DesiredState ( elementStateCondition , "desired" )
5858 {
59- IsCatchingTimeoutException = true
59+ IsCatchingTimeoutException = true ,
6060 } ;
61- return FindElements ( locator , desiredState , timeout ) ;
61+ return FindElements ( locator , desiredState , timeout , name ) ;
6262 }
6363
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 )
6565 {
6666 var foundElements = new List < IWebElement > ( ) ;
6767 var resultElements = new List < IWebElement > ( ) ;
@@ -76,14 +76,16 @@ public virtual ReadOnlyCollection<IWebElement> FindElements(By locator, DesiredS
7676 }
7777 catch ( WebDriverTimeoutException ex )
7878 {
79- HandleTimeoutException ( ex , desiredState , locator , foundElements ) ;
79+ HandleTimeoutException ( ex , desiredState , locator , foundElements , name ) ;
8080 }
8181 return resultElements . AsReadOnly ( ) ;
8282 }
8383
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 )
8585 {
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";
8789 if ( desiredState . IsCatchingTimeoutException )
8890 {
8991 if ( ! foundElements . Any ( ) )
@@ -101,12 +103,11 @@ protected virtual void HandleTimeoutException(WebDriverTimeoutException ex, Desi
101103 }
102104 else
103105 {
104- var combinedMessage = $ "{ ex . Message } : { message } ";
105106 if ( desiredState . IsThrowingNoSuchElementException && ! foundElements . Any ( ) )
106107 {
107- throw new NoSuchElementException ( combinedMessage ) ;
108+ throw new NoSuchElementException ( $ " { message } : { ex . Message } " ) ;
108109 }
109- throw new WebDriverTimeoutException ( combinedMessage ) ;
110+ throw new WebDriverTimeoutException ( $ " { ex . Message } : { message } " ) ;
110111 }
111112 }
112113
0 commit comments