1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/stdlib/html/events.go

37 lines
761 B
Go
Raw Normal View History

2018-09-23 10:33:20 +02:00
package html
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/browser"
)
func WaitElement(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)
if err != nil {
return values.None, err
}
arg := args[0]
selector := args[1].String()
timeout := values.NewInt(1000)
if len(args) > 2 {
if args[2].Type() == core.IntType {
timeout = args[2].(values.Int)
}
}
err = core.ValidateType(arg, core.HtmlDocumentType)
if err != nil {
return values.None, err
}
doc := arg.(*browser.HtmlDocument)
return values.None, doc.WaitForSelector(values.NewString(selector), timeout)
}