File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1+ using System . Linq ;
2+ using System . Threading . Tasks ;
3+ using Xunit ;
4+
5+ namespace PuppeteerSharp . Tests . ElementHandleTests
6+ {
7+ [ Collection ( "PuppeteerLoaderFixture collection" ) ]
8+ public class QuerySelectorAllTests : PuppeteerPageBaseTest
9+ {
10+ [ Fact ]
11+ public async Task ShouldQueryExistingElements ( )
12+ {
13+ await Page . SetContentAsync ( "<html><body><div>A</div><br/><div>B</div></body></html>" ) ;
14+ var html = await Page . QuerySelectorAsync ( "html" ) ;
15+ var elements = await html . QuerySelectorAllAsync ( "div" ) ;
16+ Assert . Equal ( 2 , elements . Length ) ;
17+ var tasks = elements . Select ( element => Page . EvaluateFunctionAsync < string > ( "e => e.textContent" , element ) ) ;
18+ Assert . Equal ( new [ ] { "A" , "B" } , await Task . WhenAll ( tasks ) ) ;
19+ }
20+
21+ [ Fact ]
22+ public async Task ShouldReturnEmptyArrayForNonExistingElements ( )
23+ {
24+ await Page . SetContentAsync ( "<html><body><span>A</span><br/><span>B</span></body></html>" ) ;
25+ var html = await Page . QuerySelectorAsync ( "html" ) ;
26+ var elements = await html . QuerySelectorAllAsync ( "div" ) ;
27+ Assert . Empty ( elements ) ;
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change 1313 </ItemGroup >
1414 <ItemGroup >
1515 <Folder Include =" Issues\" />
16- <Folder Include =" ElementHandleTests\" />
1716 </ItemGroup >
1817 <PropertyGroup Condition =" '$(TargetFramework)'=='net471'" >
1918 <RuntimeIdentifier >win7-x64</RuntimeIdentifier >
Original file line number Diff line number Diff line change @@ -197,7 +197,12 @@ public async Task<ElementHandle> QuerySelectorAsync(string selector)
197197 return null ;
198198 }
199199
200- internal async Task < ElementHandle [ ] > QuerySelectorAllAsync ( string selector )
200+ /// <summary>
201+ /// Runs <c>element.querySelectorAll</c> within the page. If no elements match the selector, the return value resolve to <see cref="Array.Empty{T}"/>.
202+ /// </summary>
203+ /// <param name="selector">A selector to query element for</param>
204+ /// <returns>Task which resolves to ElementHandles pointing to the frame elements</returns>
205+ public async Task < ElementHandle [ ] > QuerySelectorAllAsync ( string selector )
201206 {
202207 var arrayHandle = await ExecutionContext . EvaluateFunctionHandleAsync (
203208 "(element, selector) => element.querySelectorAll(selector)" ,
You can’t perform that action at this time.
0 commit comments