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:
@ -18,6 +18,23 @@ import (
|
||||
// @param timeout (Int, optional) - If document is passed, this param must represent timeout.
|
||||
// Otherwise not passed.
|
||||
func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitClassWhen(ctx, args, drivers.WaitEventPresence)
|
||||
}
|
||||
|
||||
// WaitClass waits for a class to disappear on a given element.
|
||||
// Stops the execution until the navigation ends or operation times out.
|
||||
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element.
|
||||
// @param selectorOrClass (String) - If document is passed, this param must represent an element selector.
|
||||
// Otherwise target class.
|
||||
// @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name.
|
||||
// Otherwise timeout.
|
||||
// @param timeout (Int, optional) - If document is passed, this param must represent timeout.
|
||||
// Otherwise not passed.
|
||||
func WaitNoClass(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitClassWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
||||
func waitClassWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 2, 4)
|
||||
|
||||
if err != nil {
|
||||
@ -74,7 +91,7 @@ func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
ctx, fn := waitTimeout(ctx, timeout)
|
||||
defer fn()
|
||||
|
||||
return values.None, doc.WaitForClassBySelector(ctx, selector, class)
|
||||
return values.None, doc.WaitForClassBySelector(ctx, selector, class, when)
|
||||
}
|
||||
|
||||
el := arg1.(drivers.HTMLElement)
|
||||
@ -93,5 +110,5 @@ func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
ctx, fn := waitTimeout(ctx, timeout)
|
||||
defer fn()
|
||||
|
||||
return values.None, el.WaitForClass(ctx, class)
|
||||
return values.None, el.WaitForClass(ctx, class, when)
|
||||
}
|
||||
|
Reference in New Issue
Block a user