@@ -15,6 +15,7 @@ internal class AriaQueryHandler : QueryHandler
1515 RegexOptions . Compiled ) ;
1616
1717 private static readonly Regex _normalizedRegex = new ( " +" , RegexOptions . Compiled ) ;
18+ private static readonly string [ ] _nonElementNodeRoles = { "StaticText" , "InlineTextBox" } ;
1819
1920 public AriaQueryHandler ( )
2021 {
@@ -26,8 +27,12 @@ public AriaQueryHandler()
2627
2728 internal override async IAsyncEnumerable < IElementHandle > QueryAllAsync ( IElementHandle element , string selector )
2829 {
29- var elementHandle = element as ElementHandle ;
3030 var ariaSelector = ParseAriaSelector ( selector ) ;
31+ if ( element is not ElementHandle elementHandle )
32+ {
33+ yield break ;
34+ }
35+
3136 var results = await QueryAXTreeAsync ( elementHandle . Realm . Environment . Client , element , ariaSelector . Name , ariaSelector . Role ) . ConfigureAwait ( false ) ;
3237
3338 foreach ( var item in results )
@@ -53,16 +58,16 @@ private static async Task<IEnumerable<AXTreeNode>> QueryAXTreeAsync(CDPSession c
5358 Role = role ,
5459 } ) . ConfigureAwait ( false ) ;
5560
56- return nodes . Nodes . Where ( ( node ) => node ? . Role ? . Value ? . ToObject < string > ( ) != "StaticText" ) ;
61+ return nodes . Nodes . Where ( node =>
62+ node ? . Role ? . Value ? . ToObject < string > ( ) is not null &&
63+ ! _nonElementNodeRoles . Contains ( node . Role . Value . ToObject < string > ( ) ) ) ;
5764 }
5865
5966 private static AriaQueryOption ParseAriaSelector ( string selector )
6067 {
61- static string NormalizeValue ( string value ) => _normalizedRegex . Replace ( value , " " ) . Trim ( ) ;
62-
6368 var knownAriaAttributes = new [ ] { "name" , "role" } ;
6469 AriaQueryOption queryOptions = new ( ) ;
65- var defaultName = _ariaSelectorAttributeRegEx . Replace ( selector , new MatchEvaluator ( ( Match match ) =>
70+ var defaultName = _ariaSelectorAttributeRegEx . Replace ( selector , match =>
6671 {
6772 var attribute = match . Groups [ "attribute" ] . Value . Trim ( ) ;
6873 if ( ! knownAriaAttributes . Contains ( attribute ) )
@@ -80,14 +85,16 @@ private static AriaQueryOption ParseAriaSelector(string selector)
8085 }
8186
8287 return string . Empty ;
83- } ) ) ;
88+ } ) ;
8489
8590 if ( ! string . IsNullOrEmpty ( defaultName ) && string . IsNullOrEmpty ( queryOptions . Name ) )
8691 {
8792 queryOptions . Name = NormalizeValue ( defaultName ) ;
8893 }
8994
9095 return queryOptions ;
96+
97+ static string NormalizeValue ( string value ) => _normalizedRegex . Replace ( value , " " ) . Trim ( ) ;
9198 }
9299 }
93100}
0 commit comments