@@ -38,6 +38,13 @@ const (
38
38
ScrollPositionNearest ScrollPosition = "nearest"
39
39
)
40
40
41
+ const (
42
+ optionButton = "button"
43
+ optionDelay = "delay"
44
+ optionClickCount = "clickCount"
45
+ optionModifiers = "modifiers"
46
+ )
47
+
41
48
// ScrollIntoViewOptions change the behavior of ScrollIntoView.
42
49
// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
43
50
type ScrollIntoViewOptions struct {
@@ -272,29 +279,33 @@ func NewElementHandleClickOptions(defaultTimeout time.Duration) *ElementHandleCl
272
279
273
280
// Parse parses the ElementHandleClickOptions from the given opts.
274
281
func (o * ElementHandleClickOptions ) Parse (ctx context.Context , opts sobek.Value ) error {
275
- rt := k6ext .Runtime (ctx )
276
282
if err := o .ElementHandleBasePointerOptions .Parse (ctx , opts ); err != nil {
277
283
return err
278
284
}
279
- if opts != nil && ! sobek .IsUndefined (opts ) && ! sobek .IsNull (opts ) {
280
- opts := opts .ToObject (rt )
281
- for _ , k := range opts .Keys () {
282
- switch k {
283
- case "button" :
284
- o .Button = opts .Get (k ).String ()
285
- case "clickCount" :
286
- o .ClickCount = opts .Get (k ).ToInteger ()
287
- case "delay" :
288
- o .Delay = opts .Get (k ).ToInteger ()
289
- case "modifiers" :
290
- var m []string
291
- if err := rt .ExportTo (opts .Get (k ), & m ); err != nil {
292
- return err
293
- }
294
- o .Modifiers = m
285
+
286
+ if ! sobekValueExists (opts ) {
287
+ return nil
288
+ }
289
+
290
+ rt := k6ext .Runtime (ctx )
291
+ obj := opts .ToObject (rt )
292
+ for _ , k := range obj .Keys () {
293
+ switch k {
294
+ case optionButton :
295
+ o .Button = obj .Get (k ).String ()
296
+ case optionClickCount :
297
+ o .ClickCount = obj .Get (k ).ToInteger ()
298
+ case optionDelay :
299
+ o .Delay = obj .Get (k ).ToInteger ()
300
+ case optionModifiers :
301
+ var m []string
302
+ if err := rt .ExportTo (obj .Get (k ), & m ); err != nil {
303
+ return fmt .Errorf ("parsing element handle click option modifiers: %w" , err )
295
304
}
305
+ o .Modifiers = m
296
306
}
297
307
}
308
+
298
309
return nil
299
310
}
300
311
0 commit comments