@@ -246,8 +246,18 @@ public Task<Response> GoToAsync(string url, int? timeout = null, WaitUntilNaviga
246246 /// <seealso cref="WaitForXPathAsync(string, WaitForSelectorOptions)"/>
247247 /// <seealso cref="Page.WaitForSelectorAsync(string, WaitForSelectorOptions)"/>
248248 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>
249- public Task < ElementHandle > WaitForSelectorAsync ( string selector , WaitForSelectorOptions options = null )
250- => MainWorld . WaitForSelectorAsync ( selector , options ) ;
249+ public async Task < ElementHandle > WaitForSelectorAsync ( string selector , WaitForSelectorOptions options = null )
250+ {
251+ var handle = await SecondaryWorld . WaitForSelectorAsync ( selector , options ) . ConfigureAwait ( false ) ;
252+ if ( handle == null )
253+ {
254+ return null ;
255+ }
256+ var mainExecutionContext = await MainWorld . GetExecutionContextAsync ( ) . ConfigureAwait ( false ) ;
257+ var result = await mainExecutionContext . AdoptElementHandleASync ( handle ) . ConfigureAwait ( false ) ;
258+ await handle . DisposeAsync ( ) . ConfigureAwait ( false ) ;
259+ return result ;
260+ }
251261
252262 /// <summary>
253263 /// Waits for a selector to be added to the DOM
@@ -277,8 +287,18 @@ public Task<ElementHandle> WaitForSelectorAsync(string selector, WaitForSelector
277287 /// <seealso cref="WaitForSelectorAsync(string, WaitForSelectorOptions)"/>
278288 /// <seealso cref="Page.WaitForXPathAsync(string, WaitForSelectorOptions)"/>
279289 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>
280- public Task < ElementHandle > WaitForXPathAsync ( string xpath , WaitForSelectorOptions options = null )
281- => MainWorld . WaitForXPathAsync ( xpath , options ) ;
290+ public async Task < ElementHandle > WaitForXPathAsync ( string xpath , WaitForSelectorOptions options = null )
291+ {
292+ var handle = await SecondaryWorld . WaitForXPathAsync ( xpath , options ) . ConfigureAwait ( false ) ;
293+ if ( handle == null )
294+ {
295+ return null ;
296+ }
297+ var mainExecutionContext = await MainWorld . GetExecutionContextAsync ( ) . ConfigureAwait ( false ) ;
298+ var result = await mainExecutionContext . AdoptElementHandleASync ( handle ) . ConfigureAwait ( false ) ;
299+ await handle . DisposeAsync ( ) . ConfigureAwait ( false ) ;
300+ return result ;
301+ }
282302
283303 /// <summary>
284304 /// Waits for a timeout
0 commit comments