1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/stdlib/html/click_all.go
Tim Voronov f39face8bf
Bugfix/click (#355)
* Added ability to use ClickBySelector with an element

* Fixes

* Increased timeout time
2019-08-24 20:26:27 -04:00

42 lines
877 B
Go

package html
import (
"context"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
// ClickAll dispatches click event on all matched element
// @param source (Open) - Open.
// @param selector (String) - Selector.
// @returns (Boolean) - Returns true if matched at least one element.
func ClickAll(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
return values.False, err
}
el, err := drivers.ToElement(args[0])
if err != nil {
return values.None, err
}
selector := values.ToString(args[1])
exists, err := el.ExistsBySelector(ctx, selector)
if err != nil {
return values.False, err
}
if !exists {
return values.False, nil
}
return values.True, el.ClickBySelectorAll(ctx, selector)
}