@@ -31,7 +31,7 @@ declare global {
3131const globalThis : any = global ;
3232
3333export interface ClickOptions {
34- root ?: puppeteer . JSHandle ;
34+ root ?: puppeteer . ElementHandle ;
3535 clickOptions ?: puppeteer . ClickOptions ;
3636 maxPixelsFromLeft ?: number ;
3737}
@@ -54,14 +54,14 @@ export const click = async (selector: string, options?: ClickOptions) => {
5454 selector , { root : options ?. root } , element => element . click ( options ?. clickOptions ) ) ;
5555} ;
5656
57- export const hover = async ( selector : string , options ?: { root ?: puppeteer . JSHandle } ) => {
57+ export const hover = async ( selector : string , options ?: { root ?: puppeteer . ElementHandle } ) => {
5858 return await performActionOnSelector ( selector , { root : options ?. root } , element => element . hover ( ) ) ;
5959} ;
6060
6161type Action = ( element : puppeteer . ElementHandle ) => Promise < void > ;
6262
6363async function performActionOnSelector (
64- selector : string , options : { root ?: puppeteer . JSHandle } , action : Action ) : Promise < puppeteer . ElementHandle > {
64+ selector : string , options : { root ?: puppeteer . ElementHandle } , action : Action ) : Promise < puppeteer . ElementHandle > {
6565 // TODO(crbug.com/1410168): we should refactor waitFor to be compatible with
6666 // Puppeteer's syntax for selectors.
6767 const queryHandlers = new Set ( [
@@ -138,7 +138,7 @@ export async function hoverElement(element: puppeteer.ElementHandle): Promise<vo
138138}
139139
140140export const doubleClick =
141- async ( selector : string , options ?: { root ?: puppeteer . JSHandle , clickOptions ?: puppeteer . ClickOptions } ) => {
141+ async ( selector : string , options ?: { root ?: puppeteer . ElementHandle , clickOptions ?: puppeteer . ClickOptions } ) => {
142142 const passedClickOptions = ( options && options . clickOptions ) || { } ;
143143 const clickOptionsWithDoubleClick : puppeteer . ClickOptions = {
144144 ...passedClickOptions ,
@@ -200,10 +200,10 @@ export const pasteText = async (text: string) => {
200200} ;
201201
202202// Get a single element handle. Uses `pierce` handler per default for piercing Shadow DOM.
203- export const $ =
204- async < ElementType extends Element = Element > ( selector : string , root ?: puppeteer . JSHandle , handler = 'pierce' ) => {
203+ export const $ = async < ElementType extends Element = Element > (
204+ selector : string , root ?: puppeteer . ElementHandle , handler = 'pierce' ) => {
205205 const { frontend} = getBrowserAndPages ( ) ;
206- const rootElement = root ? root as puppeteer . ElementHandle : frontend ;
206+ const rootElement = root ? root : frontend ;
207207 const element = await rootElement . $ ( `${ handler } /${ selector } ` ) as puppeteer . ElementHandle < ElementType > ;
208208 return element ;
209209} ;
@@ -223,7 +223,7 @@ export const $$ =
223223 * @param textContent The text content to search for.
224224 * @param root The root of the search.
225225 */
226- export const $textContent = async ( textContent : string , root ?: puppeteer . JSHandle ) => {
226+ export const $textContent = async ( textContent : string , root ?: puppeteer . ElementHandle ) => {
227227 return $ ( textContent , root , 'pierceShadowText' ) ;
228228} ;
229229
@@ -233,14 +233,14 @@ export const $textContent = async (textContent: string, root?: puppeteer.JSHandl
233233 * @param textContent The text content to search for.
234234 * @param root The root of the search.
235235 */
236- export const $$textContent = async ( textContent : string , root ?: puppeteer . JSHandle ) => {
236+ export const $$textContent = async ( textContent : string , root ?: puppeteer . ElementHandle ) => {
237237 return $$ ( textContent , root , 'pierceShadowText' ) ;
238238} ;
239239
240240export const timeout = ( duration : number ) => new Promise ( resolve => setTimeout ( resolve , duration ) ) ;
241241
242242export const getTextContent =
243- async < ElementType extends Element = Element > ( selector : string , root ?: puppeteer . JSHandle ) => {
243+ async < ElementType extends Element = Element > ( selector : string , root ?: puppeteer . ElementHandle ) => {
244244 const text = await ( await $ < ElementType > ( selector , root ) ) ?. evaluate ( node => node . textContent ) ;
245245 return text ?? undefined ;
246246} ;
@@ -266,15 +266,15 @@ export const getVisibleTextContents = async (selector: string) => {
266266} ;
267267
268268export const waitFor = async < ElementType extends Element = Element > (
269- selector : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
269+ selector : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
270270 return await asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
271271 const element = await $ < ElementType > ( selector , root , handler ) ;
272272 return ( element || undefined ) ;
273273 } , asyncScope ) , `Waiting for element matching selector '${ selector } '` ) ;
274274} ;
275275
276276export const waitForVisible = async < ElementType extends Element = Element > (
277- selector : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
277+ selector : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
278278 return await asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
279279 const element = await $ < ElementType > ( selector , root , handler ) ;
280280 const visible = await element . evaluate ( node => node . checkVisibility ( ) ) ;
@@ -283,15 +283,16 @@ export const waitForVisible = async<ElementType extends Element = Element>(
283283} ;
284284
285285export const waitForMany = async (
286- selector : string , count : number , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
286+ selector : string , count : number , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ,
287+ handler ?: string ) => {
287288 return await asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
288289 const elements = await $$ ( selector , root , handler ) ;
289290 return elements . length >= count ? elements : undefined ;
290291 } , asyncScope ) , `Waiting for ${ count } elements to match selector '${ selector } '` ) ;
291292} ;
292293
293294export const waitForNone =
294- async ( selector : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
295+ async ( selector : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) , handler ?: string ) => {
295296 return await asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
296297 const elements = await $$ ( selector , root , handler ) ;
297298 if ( elements . length === 0 ) {
@@ -302,21 +303,21 @@ export const waitForNone =
302303} ;
303304
304305export const waitForAria = < ElementType extends Element = Element > (
305- selector : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) ) => {
306+ selector : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ) => {
306307 return waitFor < ElementType > ( selector , root , asyncScope , 'aria' ) ;
307308} ;
308309
309- export const waitForAriaNone = ( selector : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) ) => {
310+ export const waitForAriaNone = ( selector : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ) => {
310311 return waitForNone ( selector , root , asyncScope , 'aria' ) ;
311312} ;
312313
313314export const waitForElementWithTextContent =
314- ( textContent : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) ) => {
315+ ( textContent : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ) => {
315316 return waitFor ( textContent , root , asyncScope , 'pierceShadowText' ) ;
316317 } ;
317318
318319export const waitForElementsWithTextContent =
319- ( textContent : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) ) => {
320+ ( textContent : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ) => {
320321 return asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
321322 const elems = await $$textContent ( textContent , root ) ;
322323 if ( elems && elems . length ) {
@@ -328,7 +329,7 @@ export const waitForElementsWithTextContent =
328329 } ;
329330
330331export const waitForNoElementsWithTextContent =
331- ( textContent : string , root ?: puppeteer . JSHandle , asyncScope = new AsyncScope ( ) ) => {
332+ ( textContent : string , root ?: puppeteer . ElementHandle , asyncScope = new AsyncScope ( ) ) => {
332333 return asyncScope . exec ( ( ) => waitForFunction ( async ( ) => {
333334 const elems = await $$textContent ( textContent , root ) ;
334335 if ( elems && elems . length === 0 ) {
@@ -374,7 +375,7 @@ export const waitForFunctionWithTries = async<T>(
374375} ;
375376
376377export const waitForWithTries = async (
377- selector : string , root ?: puppeteer . JSHandle , options : { tries : number } = {
378+ selector : string , root ?: puppeteer . ElementHandle , options : { tries : number } = {
378379 tries : Number . MAX_SAFE_INTEGER ,
379380 } ,
380381 asyncScope = new AsyncScope ( ) , handler ?: string ) => {
@@ -653,7 +654,7 @@ export const selectOption = async (select: puppeteer.ElementHandle<HTMLSelectEle
653654 } , value ) ;
654655} ;
655656
656- export const scrollElementIntoView = async ( selector : string , root ?: puppeteer . JSHandle ) => {
657+ export const scrollElementIntoView = async ( selector : string , root ?: puppeteer . ElementHandle ) => {
657658 const element = await $ ( selector , root ) ;
658659
659660 if ( ! element ) {
0 commit comments