mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
37 lines
761 B
Go
37 lines
761 B
Go
|
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)
|
||
|
}
|