@@ -241,7 +241,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
241
241
return point ;
242
242
}
243
243
244
- async _performPointerAction ( action : ( point : types . Point ) => Promise < void > , options ?: PointerActionOptions & types . WaitForOptions ) : Promise < void > {
244
+ async _performPointerAction ( action : ( point : types . Point ) => Promise < void > , options ?: PointerActionOptions & types . WaitForOptions & types . NavigateOptions ) : Promise < void > {
245
245
const { waitFor = true } = ( options || { } ) ;
246
246
if ( ! helper . isBoolean ( waitFor ) )
247
247
throw new Error ( 'waitFor option should be a boolean, got "' + ( typeof waitFor ) + '"' ) ;
@@ -260,28 +260,33 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
260
260
await action ( point ) ;
261
261
if ( restoreModifiers )
262
262
await this . _page . keyboard . _ensureModifiers ( restoreModifiers ) ;
263
- } ) ;
263
+ } , options ) ;
264
264
}
265
265
266
266
hover ( options ?: PointerActionOptions & types . WaitForOptions ) : Promise < void > {
267
267
return this . _performPointerAction ( point => this . _page . mouse . move ( point . x , point . y ) , options ) ;
268
268
}
269
269
270
- click ( options ?: ClickOptions & types . WaitForOptions ) : Promise < void > {
270
+ click ( options ?: ClickOptions & types . WaitForOptions & types . NavigateOptions ) : Promise < void > {
271
271
return this . _performPointerAction ( point => this . _page . mouse . click ( point . x , point . y , options ) , options ) ;
272
272
}
273
273
274
- dblclick ( options ?: MultiClickOptions & types . WaitForOptions ) : Promise < void > {
274
+ dblclick ( options ?: MultiClickOptions & types . WaitForOptions & types . NavigateOptions ) : Promise < void > {
275
275
return this . _performPointerAction ( point => this . _page . mouse . dblclick ( point . x , point . y , options ) , options ) ;
276
276
}
277
277
278
- tripleclick ( options ?: MultiClickOptions & types . WaitForOptions ) : Promise < void > {
278
+ tripleclick ( options ?: MultiClickOptions & types . WaitForOptions & types . NavigateOptions ) : Promise < void > {
279
279
return this . _performPointerAction ( point => this . _page . mouse . tripleclick ( point . x , point . y , options ) , options ) ;
280
280
}
281
281
282
- async select ( ...values : ( string | ElementHandle | types . SelectOption ) [ ] ) : Promise < string [ ] > {
283
- const options = values . map ( value => typeof value === 'object' ? value : { value } ) ;
284
- for ( const option of options ) {
282
+ async select ( values : string | ElementHandle | types . SelectOption | string [ ] | ElementHandle [ ] | types . SelectOption [ ] , options ?: types . NavigateOptions ) : Promise < string [ ] > {
283
+ let vals : string [ ] | ElementHandle [ ] | types . SelectOption [ ] ;
284
+ if ( ! Array . isArray ( values ) )
285
+ vals = [ values ] as ( string [ ] | ElementHandle [ ] | types . SelectOption [ ] ) ;
286
+ else
287
+ vals = values ;
288
+ const selectOptions = ( vals as any ) . map ( ( value : any ) => typeof value === 'object' ? value : { value } ) ;
289
+ for ( const option of selectOptions ) {
285
290
if ( option instanceof ElementHandle )
286
291
continue ;
287
292
if ( option . value !== undefined )
@@ -292,11 +297,11 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
292
297
assert ( helper . isNumber ( option . index ) , 'Indices must be numbers. Found index "' + option . index + '" of type "' + ( typeof option . index ) + '"' ) ;
293
298
}
294
299
return await this . _page . _frameManager . waitForNavigationsCreatedBy < string [ ] > ( async ( ) => {
295
- return this . _evaluateInUtility ( ( injected , node , ...optionsToSelect ) => injected . selectOptions ( node , optionsToSelect ) , ...options ) ;
296
- } ) ;
300
+ return this . _evaluateInUtility ( ( injected , node , ...optionsToSelect ) => injected . selectOptions ( node , optionsToSelect ) , ...selectOptions ) ;
301
+ } , options ) ;
297
302
}
298
303
299
- async fill ( value : string ) : Promise < void > {
304
+ async fill ( value : string , options ?: types . NavigateOptions ) : Promise < void > {
300
305
assert ( helper . isString ( value ) , 'Value must be string. Found value "' + value + '" of type "' + ( typeof value ) + '"' ) ;
301
306
await this . _page . _frameManager . waitForNavigationsCreatedBy ( async ( ) => {
302
307
const error = await this . _evaluateInUtility ( ( injected , node , value ) => injected . fill ( node , value ) , value ) ;
@@ -306,28 +311,35 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
306
311
await this . _page . keyboard . sendCharacters ( value ) ;
307
312
else
308
313
await this . _page . keyboard . press ( 'Delete' ) ;
309
- } ) ;
314
+ } , options ) ;
310
315
}
311
316
312
- async setInputFiles ( ... files : ( string | types . FilePayload ) [ ] ) {
317
+ async setInputFiles ( files : string | types . FilePayload | string [ ] | types . FilePayload [ ] ) {
313
318
const multiple = await this . _evaluateInUtility ( ( injected : Injected , node : Node ) => {
314
319
if ( node . nodeType !== Node . ELEMENT_NODE || ( node as Element ) . tagName !== 'INPUT' )
315
320
throw new Error ( 'Node is not an HTMLInputElement' ) ;
316
321
const input = node as HTMLInputElement ;
317
322
return input . multiple ;
318
323
} ) ;
319
- assert ( multiple || files . length <= 1 , 'Non-multiple file input can only accept single file!' ) ;
320
- const filePayloads = await Promise . all ( files . map ( async item => {
324
+ let ff : string [ ] | types . FilePayload [ ] ;
325
+ if ( ! Array . isArray ( files ) )
326
+ ff = [ files ] as string [ ] | types . FilePayload [ ] ;
327
+ else
328
+ ff = files ;
329
+ assert ( multiple || ff . length <= 1 , 'Non-multiple file input can only accept single file!' ) ;
330
+ const filePayloads : types . FilePayload [ ] = [ ] ;
331
+ for ( const item of ff ) {
321
332
if ( typeof item === 'string' ) {
322
333
const file : types . FilePayload = {
323
334
name : platform . basename ( item ) ,
324
335
type : platform . getMimeType ( item ) ,
325
336
data : await platform . readFileAsync ( item , 'base64' )
326
337
} ;
327
- return file ;
338
+ filePayloads . push ( file ) ;
339
+ } else {
340
+ filePayloads . push ( item ) ;
328
341
}
329
- return item ;
330
- } ) ) ;
342
+ }
331
343
await this . _page . _frameManager . waitForNavigationsCreatedBy ( async ( ) => {
332
344
await this . _page . _delegate . setInputFiles ( this as any as ElementHandle < HTMLInputElement > , filePayloads ) ;
333
345
} ) ;
@@ -344,29 +356,29 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
344
356
throw new Error ( errorMessage ) ;
345
357
}
346
358
347
- async type ( text : string , options ?: { delay ?: number } ) {
359
+ async type ( text : string , options ?: { delay ?: number } & types . NavigateOptions ) {
348
360
await this . _page . _frameManager . waitForNavigationsCreatedBy ( async ( ) => {
349
361
await this . focus ( ) ;
350
362
await this . _page . keyboard . type ( text , options ) ;
351
- } ) ;
363
+ } , options ) ;
352
364
}
353
365
354
- async press ( key : string , options ?: { delay ?: number , text ?: string } ) {
366
+ async press ( key : string , options ?: { delay ?: number , text ?: string } & types . NavigateOptions ) {
355
367
await this . _page . _frameManager . waitForNavigationsCreatedBy ( async ( ) => {
356
368
await this . focus ( ) ;
357
369
await this . _page . keyboard . press ( key , options ) ;
358
- } ) ;
370
+ } , options ) ;
359
371
}
360
372
361
- async check ( options ?: types . WaitForOptions ) {
373
+ async check ( options ?: types . WaitForOptions & types . NavigateOptions ) {
362
374
await this . _setChecked ( true , options ) ;
363
375
}
364
376
365
- async uncheck ( options ?: types . WaitForOptions ) {
377
+ async uncheck ( options ?: types . WaitForOptions & types . NavigateOptions ) {
366
378
await this . _setChecked ( false , options ) ;
367
379
}
368
380
369
- private async _setChecked ( state : boolean , options ?: types . WaitForOptions ) {
381
+ private async _setChecked ( state : boolean , options ?: types . WaitForOptions & types . NavigateOptions ) {
370
382
if ( await this . _evaluateInUtility ( ( injected , node ) => injected . isCheckboxChecked ( node ) ) === state )
371
383
return ;
372
384
await this . click ( options ) ;
0 commit comments