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"
|
||||
@ -14,6 +15,20 @@ import (
|
||||
// @param class (String) - String of target CSS class.
|
||||
// @param timeout (Int, optional) - Optional timeout.
|
||||
func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitClassAllWhen(ctx, args, drivers.WaitEventPresence)
|
||||
}
|
||||
|
||||
// WaitClassAll waits for a class to disappear on all matched elements.
|
||||
// Stops the execution until the navigation ends or operation times out.
|
||||
// @param doc (HTMLDocument) - Parent document.
|
||||
// @param selector (String) - String of CSS selector.
|
||||
// @param class (String) - String of target CSS class.
|
||||
// @param timeout (Int, optional) - Optional timeout.
|
||||
func WaitNoClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitClassAllWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
||||
func waitClassAllWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 3, 4)
|
||||
|
||||
if err != nil {
|
||||
@ -57,5 +72,5 @@ func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
ctx, fn := waitTimeout(ctx, timeout)
|
||||
defer fn()
|
||||
|
||||
return values.None, doc.WaitForClassBySelectorAll(ctx, selector, class)
|
||||
return values.None, doc.WaitForClassBySelectorAll(ctx, selector, class, when)
|
||||
}
|
||||
|
Reference in New Issue
Block a user