mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-05 15:16:07 +02:00
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package html
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
|
)
|
|
|
|
// WaitElement waits for element to appear in the DOM.
|
|
// Stops the execution until it finds an element or operation times out.
|
|
// @param doc (HTMLDocument) - Driver HTMLDocument.
|
|
// @param selector (String) - Target element's selector.
|
|
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
|
|
func WaitElement(_ context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 2, 3)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
doc, err := toDocument(args[0])
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
selector := args[1].String()
|
|
timeout := values.NewInt(defaultTimeout)
|
|
|
|
if len(args) > 2 {
|
|
err = core.ValidateType(args[2], types.Int)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
timeout = args[2].(values.Int)
|
|
}
|
|
|
|
return values.None, doc.WaitForSelector(values.NewString(selector), timeout)
|
|
}
|