mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
5620be211c
* Renamed DOCUMENT to PAGE * Added PageLoadParams * Added PageLoadParams * Renamed LoadPageParams -> PageLoadParams * Added support for context.Done() (#201) * Bug/#189 operators precedence (#202) * Fixed math operators precedence * Fixed logical operators precedence * Fixed array operator * Added support for parentheses to enforce a different operator evaluation order * Feature/#200 drivers (#209) * Added new interfaces * Renamed dynamic to cdp driver * Renamed drivers * Added ELEMENT_EXISTS function (#210) * Renamed back PAGE to DOCUMENT (#211) * Added Getter and Setter interfaces
103 lines
2.4 KiB
Go
103 lines
2.4 KiB
Go
package html
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
// WaitClass waits for a class to appear 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 WaitClass(_ context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 2, 4)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
// document or element
|
|
err = core.ValidateType(args[0], core.HTMLDocumentType, core.HTMLElementType)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
// selector or class
|
|
err = core.ValidateType(args[1], core.StringType)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
timeout := values.NewInt(defaultTimeout)
|
|
|
|
// lets figure out what is passed as 1st argument
|
|
switch args[0].(type) {
|
|
case values.DHTMLDocument:
|
|
// revalidate args with more accurate amount
|
|
err := core.ValidateArgs(args, 3, 4)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
// class
|
|
err = core.ValidateType(args[2], core.StringType)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
doc, ok := args[0].(values.DHTMLDocument)
|
|
|
|
if !ok {
|
|
return values.None, core.Errors(core.ErrInvalidType, ErrNotDynamic)
|
|
}
|
|
|
|
selector := args[1].(values.String)
|
|
class := args[2].(values.String)
|
|
|
|
if len(args) == 4 {
|
|
err = core.ValidateType(args[3], core.IntType)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
timeout = args[3].(values.Int)
|
|
}
|
|
|
|
return values.None, doc.WaitForClass(selector, class, timeout)
|
|
case values.DHTMLNode:
|
|
el, ok := args[0].(values.DHTMLNode)
|
|
|
|
if !ok {
|
|
return values.None, core.Errors(core.ErrInvalidType, ErrNotDynamic)
|
|
}
|
|
|
|
class := args[1].(values.String)
|
|
|
|
if len(args) == 3 {
|
|
err = core.ValidateType(args[2], core.IntType)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
timeout = args[2].(values.Int)
|
|
}
|
|
|
|
return values.None, el.WaitForClass(class, timeout)
|
|
default:
|
|
return values.None, core.Errors(core.ErrInvalidType, ErrNotDynamic)
|
|
}
|
|
}
|