mirror of
https://github.com/MontFerret/ferret.git
synced 2025-06-23 00:28:10 +02:00
Feature/#229 wait no element (#249)
* Added possibility to wait for an element or a class absence
This commit is contained in:
@ -2,6 +2,7 @@ package html
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/MontFerret/ferret/pkg/drivers"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
@ -13,6 +14,19 @@ import (
|
||||
// @param selector (String) - Target element's selector.
|
||||
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
|
||||
func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitElementWhen(ctx, args, drivers.WaitEventPresence)
|
||||
}
|
||||
|
||||
// WaitNoElements waits for element to disappear in the DOM.
|
||||
// Stops the execution until it does not find 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 WaitNoElement(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitElementWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
||||
func waitElementWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 2, 3)
|
||||
|
||||
if err != nil {
|
||||
@ -41,5 +55,5 @@ func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
ctx, fn := waitTimeout(ctx, timeout)
|
||||
defer fn()
|
||||
|
||||
return values.None, doc.WaitForSelector(ctx, values.NewString(selector))
|
||||
return values.None, doc.WaitForElement(ctx, values.NewString(selector), when)
|
||||
}
|
||||
|
Reference in New Issue
Block a user