@@ -23,30 +23,35 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
2323 }
2424 ILocator locator = page . Locator ( "body" ) ;
2525 int count = 0 ;
26+ var keyword = string . Empty ;
2627
2728 // check if selector is specified
2829 if ( location . Selector != null )
2930 {
31+ keyword = location . Selector ;
3032 locator = locator . Locator ( location . Selector ) ;
3133 count = await locator . CountAsync ( ) ;
3234 }
3335
3436 if ( location . Tag != null )
3537 {
38+ keyword = location . Tag ;
3639 locator = page . Locator ( location . Tag ) ;
3740 count = await locator . CountAsync ( ) ;
3841 }
3942
4043 // try attribute
4144 if ( ! string . IsNullOrEmpty ( location . AttributeName ) )
4245 {
43- locator = locator . Locator ( $ "[{ location . AttributeName } ='{ location . AttributeValue } ']") ;
46+ keyword = $ "[{ location . AttributeName } ='{ location . AttributeValue } ']";
47+ locator = locator . Locator ( keyword ) ;
4448 count = await locator . CountAsync ( ) ;
4549 }
4650
4751 // Retrieve the page raw html and infer the element path
4852 if ( ! string . IsNullOrEmpty ( location . Text ) )
4953 {
54+ keyword = location . Text ;
5055 var text = location . Text . Replace ( "(" , "\\ (" ) . Replace ( ")" , "\\ )" ) ;
5156 var regexExpression = location . MatchRule . ToLower ( ) switch
5257 {
@@ -69,6 +74,7 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
6974
7075 if ( location . Index >= 0 )
7176 {
77+ keyword = $ "Index:{ location . Index } ";
7278 locator = locator . Nth ( location . Index ) ;
7379 count = await locator . CountAsync ( ) ;
7480 }
@@ -77,12 +83,12 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
7783 {
7884 if ( location . IgnoreIfNotFound )
7985 {
80- result . Message = $ "Can't locate element by keyword { location . Text } and Ignored";
86+ result . Message = $ "Can't locate element by keyword { keyword } and Ignored";
8187 _logger . LogWarning ( result . Message ) ;
8288 }
8389 else
8490 {
85- result . Message = $ "Can't locate element by keyword { location . Text } ";
91+ result . Message = $ "Can't locate element by keyword { keyword } ";
8692 _logger . LogError ( result . Message ) ;
8793 }
8894
0 commit comments