2018-10-07 04:33:39 +02:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-14 19:06:27 +02:00
|
|
|
|
2019-02-20 01:10:18 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
2018-10-07 04:33:39 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
2019-09-07 07:59:32 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
2018-10-07 04:33:39 +02:00
|
|
|
)
|
|
|
|
|
2018-10-14 19:06:27 +02:00
|
|
|
// ClickAll dispatches click event on all matched element
|
2019-06-19 23:58:56 +02:00
|
|
|
// @param source (Open) - Open.
|
2018-10-14 19:06:27 +02:00
|
|
|
// @param selector (String) - Selector.
|
2019-09-07 07:59:32 +02:00
|
|
|
// @param count (Int, optional) - Optional count of clicks.
|
2018-10-14 19:06:27 +02:00
|
|
|
// @returns (Boolean) - Returns true if matched at least one element.
|
2019-02-21 04:24:05 +02:00
|
|
|
func ClickAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
2019-09-07 07:59:32 +02:00
|
|
|
err := core.ValidateArgs(args, 2, 3)
|
2018-10-07 04:33:39 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.False, err
|
|
|
|
}
|
|
|
|
|
2019-08-25 02:26:27 +02:00
|
|
|
el, err := drivers.ToElement(args[0])
|
2018-10-07 04:33:39 +02:00
|
|
|
|
|
|
|
if err != nil {
|
2019-09-07 07:59:32 +02:00
|
|
|
return values.False, err
|
2018-10-07 04:33:39 +02:00
|
|
|
}
|
|
|
|
|
2019-07-26 19:22:06 +02:00
|
|
|
selector := values.ToString(args[1])
|
2018-10-07 04:33:39 +02:00
|
|
|
|
2019-08-25 02:26:27 +02:00
|
|
|
exists, err := el.ExistsBySelector(ctx, selector)
|
2019-07-26 19:22:06 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.False, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
return values.False, nil
|
|
|
|
}
|
|
|
|
|
2019-09-07 07:59:32 +02:00
|
|
|
count := values.NewInt(1)
|
|
|
|
|
|
|
|
if len(args) == 3 {
|
|
|
|
err := core.ValidateType(args[2], types.Int)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.False, err
|
|
|
|
}
|
|
|
|
|
|
|
|
count = values.ToInt(args[2])
|
|
|
|
}
|
|
|
|
|
|
|
|
return values.True, el.ClickBySelectorAll(ctx, selector, count)
|
2018-10-07 04:33:39 +02:00
|
|
|
}
|