1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-01-20 03:29:51 +02:00

Merge pull request #380 from MontFerret/refactoring/html-element

Removed redundant element value caching
This commit is contained in:
Tim Voronov 2019-09-07 14:36:16 -04:00 committed by GitHub
commit df390a629a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 144 additions and 148 deletions

View File

@ -268,7 +268,7 @@ func (doc *HTMLDocument) ExistsBySelector(ctx context.Context, selector values.S
} }
func (doc *HTMLDocument) GetTitle() values.String { func (doc *HTMLDocument) GetTitle() values.String {
value, err := doc.exec.ReadProperty(context.Background(), doc.element.id.objectID, "title") value, err := doc.exec.ReadProperty(context.Background(), doc.element.id.ObjectID, "title")
if err != nil { if err != nil {
doc.logError(errors.Wrap(err, "failed to read document title")) doc.logError(errors.Wrap(err, "failed to read document title"))

View File

@ -10,6 +10,13 @@ import (
"sync" "sync"
"time" "time"
"github.com/mafredri/cdp"
"github.com/mafredri/cdp/protocol/dom"
"github.com/mafredri/cdp/protocol/runtime"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"golang.org/x/net/html"
"github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
"github.com/MontFerret/ferret/pkg/drivers/cdp/events" "github.com/MontFerret/ferret/pkg/drivers/cdp/events"
@ -19,21 +26,14 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
"github.com/mafredri/cdp"
"github.com/mafredri/cdp/protocol/dom"
"github.com/mafredri/cdp/protocol/runtime"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"golang.org/x/net/html"
) )
var emptyNodeID = dom.NodeID(0) var emptyNodeID = dom.NodeID(0)
type ( type (
HTMLElementIdentity struct { HTMLElementIdentity struct {
nodeID dom.NodeID NodeID dom.NodeID
objectID runtime.RemoteObjectID ObjectID runtime.RemoteObjectID
} }
HTMLElement struct { HTMLElement struct {
@ -49,7 +49,6 @@ type (
nodeName values.String nodeName values.String
innerHTML *common.LazyValue innerHTML *common.LazyValue
innerText *common.LazyValue innerText *common.LazyValue
value core.Value
attributes *common.LazyValue attributes *common.LazyValue
style *common.LazyValue style *common.LazyValue
children []HTMLElementIdentity children []HTMLElementIdentity
@ -83,10 +82,6 @@ func LoadHTMLElement(
return nil, core.Error(core.ErrNotFound, fmt.Sprintf("element %d", nodeID)) return nil, core.Error(core.ErrNotFound, fmt.Sprintf("element %d", nodeID))
} }
id := HTMLElementIdentity{}
id.nodeID = nodeID
id.objectID = *obj.Object.ObjectID
return LoadHTMLElementWithID( return LoadHTMLElementWithID(
ctx, ctx,
logger, logger,
@ -94,7 +89,10 @@ func LoadHTMLElement(
broker, broker,
input, input,
exec, exec,
id, HTMLElementIdentity{
NodeID: nodeID,
ObjectID: *obj.Object.ObjectID,
},
) )
} }
@ -111,18 +109,12 @@ func LoadHTMLElementWithID(
ctx, ctx,
dom. dom.
NewDescribeNodeArgs(). NewDescribeNodeArgs().
SetObjectID(id.objectID). SetObjectID(id.ObjectID).
SetDepth(1), SetDepth(1),
) )
if err != nil { if err != nil {
return nil, core.Error(err, strconv.Itoa(int(id.nodeID))) return nil, core.Error(err, strconv.Itoa(int(id.NodeID)))
}
var val string
if node.Node.Value != nil {
val = *node.Node.Value
} }
return NewHTMLElement( return NewHTMLElement(
@ -134,7 +126,6 @@ func LoadHTMLElementWithID(
id, id,
node.Node.NodeType, node.Node.NodeType,
node.Node.NodeName, node.Node.NodeName,
val,
createChildrenArray(node.Node.Children), createChildrenArray(node.Node.Children),
), nil ), nil
} }
@ -148,7 +139,6 @@ func NewHTMLElement(
id HTMLElementIdentity, id HTMLElementIdentity,
nodeType int, nodeType int,
nodeName string, nodeName string,
value string,
children []HTMLElementIdentity, children []HTMLElementIdentity,
) *HTMLElement { ) *HTMLElement {
el := new(HTMLElement) el := new(HTMLElement)
@ -165,9 +155,7 @@ func NewHTMLElement(
el.innerText = common.NewLazyValue(el.loadInnerText) el.innerText = common.NewLazyValue(el.loadInnerText)
el.attributes = common.NewLazyValue(el.loadAttrs) el.attributes = common.NewLazyValue(el.loadAttrs)
el.style = common.NewLazyValue(el.parseStyle) el.style = common.NewLazyValue(el.parseStyle)
el.value = values.EmptyString
el.loadedChildren = common.NewLazyValue(el.loadChildren) el.loadedChildren = common.NewLazyValue(el.loadChildren)
el.value = values.NewString(value)
el.children = children el.children = children
broker.AddEventListener(events.EventReload, el.handlePageReload) broker.AddEventListener(events.EventReload, el.handlePageReload)
@ -243,7 +231,7 @@ func (el *HTMLElement) Hash() uint64 {
h.Write([]byte(el.Type().String())) h.Write([]byte(el.Type().String()))
h.Write([]byte(":")) h.Write([]byte(":"))
h.Write([]byte(strconv.Itoa(int(el.id.nodeID)))) h.Write([]byte(strconv.Itoa(int(el.id.NodeID))))
return h.Sum64() return h.Sum64()
} }
@ -269,15 +257,7 @@ func (el *HTMLElement) GetValue(ctx context.Context) (core.Value, error) {
return values.None, drivers.ErrDetached return values.None, drivers.ErrDetached
} }
val, err := el.exec.ReadProperty(ctx, el.id.objectID, "value") return el.exec.ReadProperty(ctx, el.id.ObjectID, "value")
if err != nil {
return values.None, err
}
el.value = val
return val, nil
} }
func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error { func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error {
@ -285,7 +265,7 @@ func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error {
return drivers.ErrDetached return drivers.ErrDetached
} }
return el.client.DOM.SetNodeValue(ctx, dom.NewSetNodeValueArgs(el.id.nodeID, value.String())) return el.client.DOM.SetNodeValue(ctx, dom.NewSetNodeValueArgs(el.id.NodeID, value.String()))
} }
func (el *HTMLElement) GetNodeType() values.Int { func (el *HTMLElement) GetNodeType() values.Int {
@ -437,7 +417,7 @@ func (el *HTMLElement) SetAttributes(ctx context.Context, attrs *values.Object)
func (el *HTMLElement) SetAttribute(ctx context.Context, name, value values.String) error { func (el *HTMLElement) SetAttribute(ctx context.Context, name, value values.String) error {
return el.client.DOM.SetAttributeValue( return el.client.DOM.SetAttributeValue(
ctx, ctx,
dom.NewSetAttributeValueArgs(el.id.nodeID, string(name), string(value)), dom.NewSetAttributeValueArgs(el.id.NodeID, string(name), string(value)),
) )
} }
@ -445,7 +425,7 @@ func (el *HTMLElement) RemoveAttribute(ctx context.Context, names ...values.Stri
for _, name := range names { for _, name := range names {
err := el.client.DOM.RemoveAttribute( err := el.client.DOM.RemoveAttribute(
ctx, ctx,
dom.NewRemoveAttributeArgs(el.id.nodeID, name.String()), dom.NewRemoveAttributeArgs(el.id.NodeID, name.String()),
) )
if err != nil { if err != nil {
@ -481,7 +461,7 @@ func (el *HTMLElement) QuerySelector(ctx context.Context, selector values.String
return values.None, drivers.ErrDetached return values.None, drivers.ErrDetached
} }
selectorArgs := dom.NewQuerySelectorArgs(el.id.nodeID, selector.String()) selectorArgs := dom.NewQuerySelectorArgs(el.id.NodeID, selector.String())
found, err := el.client.DOM.QuerySelector(ctx, selectorArgs) found, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
if err != nil { if err != nil {
@ -506,7 +486,7 @@ func (el *HTMLElement) QuerySelectorAll(ctx context.Context, selector values.Str
return values.NewArray(0), drivers.ErrDetached return values.NewArray(0), drivers.ErrDetached
} }
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.nodeID, selector.String()) selectorArgs := dom.NewQuerySelectorAllArgs(el.id.NodeID, selector.String())
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs) res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
if err != nil { if err != nil {
@ -554,7 +534,7 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
out, err := el.exec.EvalWithArgumentsAndReturnReference(ctx, templates.XPath(), out, err := el.exec.EvalWithArgumentsAndReturnReference(ctx, templates.XPath(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: json.RawMessage(exp), Value: json.RawMessage(exp),
@ -633,8 +613,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
el.input, el.input,
el.exec, el.exec,
HTMLElementIdentity{ HTMLElementIdentity{
nodeID: repl.NodeID, NodeID: repl.NodeID,
objectID: *descr.Value.ObjectID, ObjectID: *descr.Value.ObjectID,
}, },
) )
@ -665,8 +645,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
el.input, el.input,
el.exec, el.exec,
HTMLElementIdentity{ HTMLElementIdentity{
nodeID: repl.NodeID, NodeID: repl.NodeID,
objectID: *out.ObjectID, ObjectID: *out.ObjectID,
}, },
) )
default: default:
@ -713,7 +693,7 @@ func (el *HTMLElement) GetInnerTextBySelector(ctx context.Context, selector valu
ctx, ctx,
templates.GetInnerTextBySelector(), templates.GetInnerTextBySelector(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -748,7 +728,7 @@ func (el *HTMLElement) SetInnerTextBySelector(ctx context.Context, selector, inn
ctx, ctx,
templates.SetInnerTextBySelector(), templates.SetInnerTextBySelector(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -774,7 +754,7 @@ func (el *HTMLElement) GetInnerTextBySelectorAll(ctx context.Context, selector v
ctx, ctx,
templates.GetInnerTextBySelectorAll(), templates.GetInnerTextBySelectorAll(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -833,7 +813,7 @@ func (el *HTMLElement) GetInnerHTMLBySelector(ctx context.Context, selector valu
ctx, ctx,
templates.GetInnerHTMLBySelector(), templates.GetInnerHTMLBySelector(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -868,7 +848,7 @@ func (el *HTMLElement) SetInnerHTMLBySelector(ctx context.Context, selector, inn
ctx, ctx,
templates.SetInnerHTMLBySelector(), templates.SetInnerHTMLBySelector(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -894,7 +874,7 @@ func (el *HTMLElement) GetInnerHTMLBySelectorAll(ctx context.Context, selector v
ctx, ctx,
templates.GetInnerHTMLBySelectorAll(), templates.GetInnerHTMLBySelectorAll(),
runtime.CallArgument{ runtime.CallArgument{
ObjectID: &el.id.objectID, ObjectID: &el.id.ObjectID,
}, },
runtime.CallArgument{ runtime.CallArgument{
Value: sel, Value: sel,
@ -919,7 +899,7 @@ func (el *HTMLElement) CountBySelector(ctx context.Context, selector values.Stri
return values.ZeroInt, drivers.ErrDetached return values.ZeroInt, drivers.ErrDetached
} }
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.nodeID, selector.String()) selectorArgs := dom.NewQuerySelectorAllArgs(el.id.NodeID, selector.String())
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs) res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
if err != nil { if err != nil {
@ -935,7 +915,7 @@ func (el *HTMLElement) ExistsBySelector(ctx context.Context, selector values.Str
} }
// TODO: Can we use RemoteObjectID or BackendID instead of NodeId? // TODO: Can we use RemoteObjectID or BackendID instead of NodeId?
selectorArgs := dom.NewQuerySelectorArgs(el.id.nodeID, selector.String()) selectorArgs := dom.NewQuerySelectorArgs(el.id.NodeID, selector.String())
res, err := el.client.DOM.QuerySelector(ctx, selectorArgs) res, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
if err != nil { if err != nil {
@ -1027,15 +1007,15 @@ func (el *HTMLElement) WaitForStyle(ctx context.Context, name values.String, val
} }
func (el *HTMLElement) Click(ctx context.Context, count values.Int) error { func (el *HTMLElement) Click(ctx context.Context, count values.Int) error {
return el.input.Click(ctx, el.id.objectID, int(count)) return el.input.Click(ctx, el.id.ObjectID, int(count))
} }
func (el *HTMLElement) ClickBySelector(ctx context.Context, selector values.String, count values.Int) error { func (el *HTMLElement) ClickBySelector(ctx context.Context, selector values.String, count values.Int) error {
return el.input.ClickBySelector(ctx, el.id.nodeID, selector.String(), int(count)) return el.input.ClickBySelector(ctx, el.id.NodeID, selector.String(), int(count))
} }
func (el *HTMLElement) ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error { func (el *HTMLElement) ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error {
return el.input.ClickBySelectorAll(ctx, el.id.nodeID, selector.String(), int(count)) return el.input.ClickBySelectorAll(ctx, el.id.NodeID, selector.String(), int(count))
} }
func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values.Int) error { func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values.Int) error {
@ -1043,7 +1023,7 @@ func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values
return core.Error(core.ErrInvalidOperation, "element is not an <input> element.") return core.Error(core.ErrInvalidOperation, "element is not an <input> element.")
} }
return el.input.Type(ctx, el.id.objectID, input.TypeParams{ return el.input.Type(ctx, el.id.ObjectID, input.TypeParams{
Text: value.String(), Text: value.String(),
Clear: false, Clear: false,
Delay: time.Duration(delay) * time.Millisecond, Delay: time.Duration(delay) * time.Millisecond,
@ -1051,7 +1031,7 @@ func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values
} }
func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error { func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error {
return el.input.TypeBySelector(ctx, el.id.nodeID, selector.String(), input.TypeParams{ return el.input.TypeBySelector(ctx, el.id.NodeID, selector.String(), input.TypeParams{
Text: value.String(), Text: value.String(),
Clear: false, Clear: false,
Delay: time.Duration(delay) * time.Millisecond, Delay: time.Duration(delay) * time.Millisecond,
@ -1059,31 +1039,31 @@ func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.Stri
} }
func (el *HTMLElement) Clear(ctx context.Context) error { func (el *HTMLElement) Clear(ctx context.Context) error {
return el.input.Clear(ctx, el.id.objectID) return el.input.Clear(ctx, el.id.ObjectID)
} }
func (el *HTMLElement) ClearBySelector(ctx context.Context, selector values.String) error { func (el *HTMLElement) ClearBySelector(ctx context.Context, selector values.String) error {
return el.input.ClearBySelector(ctx, el.id.nodeID, selector.String()) return el.input.ClearBySelector(ctx, el.id.NodeID, selector.String())
} }
func (el *HTMLElement) Select(ctx context.Context, value *values.Array) (*values.Array, error) { func (el *HTMLElement) Select(ctx context.Context, value *values.Array) (*values.Array, error) {
return el.input.Select(ctx, el.id.objectID, value) return el.input.Select(ctx, el.id.ObjectID, value)
} }
func (el *HTMLElement) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) { func (el *HTMLElement) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) {
return el.input.SelectBySelector(ctx, el.id.nodeID, selector.String(), value) return el.input.SelectBySelector(ctx, el.id.NodeID, selector.String(), value)
} }
func (el *HTMLElement) ScrollIntoView(ctx context.Context) error { func (el *HTMLElement) ScrollIntoView(ctx context.Context) error {
return el.input.ScrollIntoView(ctx, el.id.objectID) return el.input.ScrollIntoView(ctx, el.id.ObjectID)
} }
func (el *HTMLElement) Focus(ctx context.Context) error { func (el *HTMLElement) Focus(ctx context.Context) error {
return el.input.Focus(ctx, el.id.objectID) return el.input.Focus(ctx, el.id.ObjectID)
} }
func (el *HTMLElement) FocusBySelector(ctx context.Context, selector values.String) error { func (el *HTMLElement) FocusBySelector(ctx context.Context, selector values.String) error {
return el.input.FocusBySelector(ctx, el.id.nodeID, selector.String()) return el.input.FocusBySelector(ctx, el.id.NodeID, selector.String())
} }
func (el *HTMLElement) Blur(ctx context.Context) error { func (el *HTMLElement) Blur(ctx context.Context) error {
@ -1095,11 +1075,11 @@ func (el *HTMLElement) BlurBySelector(ctx context.Context, selector values.Strin
} }
func (el *HTMLElement) Hover(ctx context.Context) error { func (el *HTMLElement) Hover(ctx context.Context) error {
return el.input.MoveMouse(ctx, el.id.objectID) return el.input.MoveMouse(ctx, el.id.ObjectID)
} }
func (el *HTMLElement) HoverBySelector(ctx context.Context, selector values.String) error { func (el *HTMLElement) HoverBySelector(ctx context.Context, selector values.String) error {
return el.input.MoveMouseBySelector(ctx, el.id.nodeID, selector.String()) return el.input.MoveMouseBySelector(ctx, el.id.NodeID, selector.String())
} }
func (el *HTMLElement) IsDetached() values.Boolean { func (el *HTMLElement) IsDetached() values.Boolean {
@ -1154,7 +1134,7 @@ func (el *HTMLElement) loadInnerText(ctx context.Context) (core.Value, error) {
} }
func (el *HTMLElement) loadAttrs(ctx context.Context) (core.Value, error) { func (el *HTMLElement) loadAttrs(ctx context.Context) (core.Value, error) {
repl, err := el.client.DOM.GetAttributes(ctx, dom.NewGetAttributesArgs(el.id.nodeID)) repl, err := el.client.DOM.GetAttributes(ctx, dom.NewGetAttributesArgs(el.id.NodeID))
if err != nil { if err != nil {
return values.None, err return values.None, err
@ -1178,7 +1158,7 @@ func (el *HTMLElement) loadChildren(ctx context.Context) (core.Value, error) {
el.events, el.events,
el.input, el.input,
el.exec, el.exec,
childID.nodeID, childID.NodeID,
) )
if err != nil { if err != nil {
@ -1224,7 +1204,7 @@ func (el *HTMLElement) handleAttrModified(ctx context.Context, message interface
} }
// it's not for this el // it's not for this el
if reply.NodeID != el.id.nodeID { if reply.NodeID != el.id.NodeID {
return return
} }
@ -1268,7 +1248,7 @@ func (el *HTMLElement) handleAttrRemoved(ctx context.Context, message interface{
} }
// it's not for this el // it's not for this el
if reply.NodeID != el.id.nodeID { if reply.NodeID != el.id.NodeID {
return return
} }
@ -1310,7 +1290,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
return return
} }
if reply.NodeID != el.id.nodeID { if reply.NodeID != el.id.NodeID {
return return
} }
@ -1323,7 +1303,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
node, err := el.client.DOM.DescribeNode( node, err := el.client.DOM.DescribeNode(
ctx, ctx,
dom.NewDescribeNodeArgs().SetObjectID(el.id.objectID), dom.NewDescribeNodeArgs().SetObjectID(el.id.ObjectID),
) )
if err != nil { if err != nil {
@ -1342,7 +1322,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
return return
} }
if reply.ParentNodeID != el.id.nodeID { if reply.ParentNodeID != el.id.NodeID {
return return
} }
@ -1358,7 +1338,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
defer el.mu.Unlock() defer el.mu.Unlock()
for idx, id := range el.children { for idx, id := range el.children {
if id.nodeID == prevID { if id.NodeID == prevID {
targetIDx = idx targetIDx = idx
break break
} }
@ -1369,7 +1349,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
} }
nextIdentity := HTMLElementIdentity{ nextIdentity := HTMLElementIdentity{
nodeID: reply.Node.NodeID, NodeID: reply.Node.NodeID,
} }
arr := el.children arr := el.children
@ -1403,7 +1383,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
return return
} }
if reply.ParentNodeID != el.id.nodeID { if reply.ParentNodeID != el.id.NodeID {
return return
} }
@ -1418,7 +1398,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
defer el.mu.Unlock() defer el.mu.Unlock()
for idx, id := range el.children { for idx, id := range el.children {
if id.nodeID == targetID { if id.NodeID == targetID {
targetIDx = idx targetIDx = idx
break break
} }
@ -1440,7 +1420,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
el.logger.Error(). el.logger.Error().
Timestamp(). Timestamp().
Err(err). Err(err).
Int("nodeID", int(el.id.nodeID)). Int("nodeID", int(el.id.NodeID)).
Msg("failed to update element") Msg("failed to update element")
return return
@ -1458,7 +1438,7 @@ func (el *HTMLElement) logError(err error) *zerolog.Event {
return el.logger. return el.logger.
Error(). Error().
Timestamp(). Timestamp().
Int("nodeID", int(el.id.nodeID)). Int("nodeID", int(el.id.NodeID)).
Str("objectID", string(el.id.objectID)). Str("objectID", string(el.id.ObjectID)).
Err(err) Err(err)
} }

View File

@ -71,10 +71,10 @@ func parseAttrs(attrs []string) *values.Object {
func setInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerHTML values.String) error { func setInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerHTML values.String) error {
var objID *runtime.RemoteObjectID var objID *runtime.RemoteObjectID
if id.objectID != "" { if id.ObjectID != "" {
objID = &id.objectID objID = &id.ObjectID
} else { } else {
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID)) repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
if err != nil { if err != nil {
return err return err
@ -110,10 +110,10 @@ func getInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
if nodeType != html.DocumentNode { if nodeType != html.DocumentNode {
var objID runtime.RemoteObjectID var objID runtime.RemoteObjectID
if id.objectID != "" { if id.ObjectID != "" {
objID = id.objectID objID = id.ObjectID
} else { } else {
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID)) repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
if err != nil { if err != nil {
return "", err return "", err
@ -147,10 +147,10 @@ func getInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
func setInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerText values.String) error { func setInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerText values.String) error {
var objID *runtime.RemoteObjectID var objID *runtime.RemoteObjectID
if id.objectID != "" { if id.ObjectID != "" {
objID = &id.objectID objID = &id.ObjectID
} else { } else {
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID)) repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
if err != nil { if err != nil {
return err return err
@ -186,10 +186,10 @@ func getInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
if nodeType != html.DocumentNode { if nodeType != html.DocumentNode {
var objID runtime.RemoteObjectID var objID runtime.RemoteObjectID
if id.objectID != "" { if id.ObjectID != "" {
objID = id.objectID objID = id.ObjectID
} else { } else {
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID)) repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
if err != nil { if err != nil {
return "", err return "", err
@ -238,7 +238,7 @@ func createChildrenArray(nodes []dom.Node) []HTMLElementIdentity {
for idx, child := range nodes { for idx, child := range nodes {
child := child child := child
children[idx] = HTMLElementIdentity{ children[idx] = HTMLElementIdentity{
nodeID: child.NodeID, NodeID: child.NodeID,
} }
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// AttributeGet gets single or more attribute(s) of a given element. // ATTR_GET gets single or more attribute(s) of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param names (...String) - Attribute name(s). // @param names (...String) - Attribute name(s).
// @returns Object - Key-value pairs of attribute values. // @returns Object - Key-value pairs of attribute values.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// AttributeRemove removes single or more attribute(s) of a given element. // ATTR_REMOVE removes single or more attribute(s) of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param names (...String) - Attribute name(s). // @param names (...String) - Attribute name(s).
func AttributeRemove(ctx context.Context, args ...core.Value) (core.Value, error) { func AttributeRemove(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// AttributeSet sets or updates a single or more attribute(s) of a given element. // ATTR_SET sets or updates a single or more attribute(s) of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param nameOrObj (String | Object) - Attribute name or an object representing a key-value pair of attributes. // @param nameOrObj (String | Object) - Attribute name or an object representing a key-value pair of attributes.
// @param value (String) - If a second parameter is a string value, this parameter represent an attribute value. // @param value (String) - If a second parameter is a string value, this parameter represent an attribute value.

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// InputClear clears a value from an underlying input element. // INPUT_CLEAR clears a value from an underlying input element.
// @param source (HTMLPage | HTMLDocument | HTMLElement) - Event target. // @param source (HTMLPage | HTMLDocument | HTMLElement) - Event target.
// @param selector (String, options) - Selector. // @param selector (String, options) - Selector.
func InputClear(ctx context.Context, args ...core.Value) (core.Value, error) { func InputClear(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Click dispatches click event on a given element // CLICK dispatches click event on a given element
// @param source (Open | GetElement) - Event source. // @param source (Open | GetElement) - Event source.
// @param selectorOrCount (String | Int, optional) - Optional selector or count of clicks. // @param selectorOrCount (String | Int, optional) - Optional selector or count of clicks.
// @param count (Int, optional) - Optional count of clicks. // @param count (Int, optional) - Optional count of clicks.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// ClickAll dispatches click event on all matched element // CLICK_ALL dispatches click event on all matched element
// @param source (Open) - Open. // @param source (Open) - Open.
// @param selector (String) - Selector. // @param selector (String) - Selector.
// @param count (Int, optional) - Optional count of clicks. // @param count (Int, optional) - Optional count of clicks.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// CookieSet gets a cookie from a given page by name. // COOKIE_DEL gets a cookie from a given page by name.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.
// @param cookie (...HTTPCookie|String) - Cookie or cookie name to delete. // @param cookie (...HTTPCookie|String) - Cookie or cookie name to delete.
func CookieDel(ctx context.Context, args ...core.Value) (core.Value, error) { func CookieDel(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// CookieSet gets a cookie from a given page by name. // COOKIE_GET gets a cookie from a given page by name.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.
// @param name (String) - Cookie or cookie name to delete. // @param name (String) - Cookie or cookie name to delete.
func CookieGet(ctx context.Context, args ...core.Value) (core.Value, error) { func CookieGet(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// CookieSet sets cookies to a given page // COOKIE_SET sets cookies to a given page
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.
// @param cookie... (HTTPCookie) - Target cookies. // @param cookie... (HTTPCookie) - Target cookies.
func CookieSet(ctx context.Context, args ...core.Value) (core.Value, error) { func CookieSet(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -18,7 +18,7 @@ type PageLoadParams struct {
Timeout time.Duration Timeout time.Duration
} }
// Open opens an HTML page by a given url. // DOCUMENT opens an HTML page by a given url.
// By default, loads a page by http call - resulted page does not support any interactions. // By default, loads a page by http call - resulted page does not support any interactions.
// @param params (Object) - Optional, An object containing the following properties : // @param params (Object) - Optional, An object containing the following properties :
// driver (String) - Optional, driver name. // driver (String) - Optional, driver name.

View File

@ -10,7 +10,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Download a resource from the given GetURL. // DOWNLOAD downloads a resource from the given GetURL.
// @param GetURL (String) - GetURL to download. // @param GetURL (String) - GetURL to download.
// @returns data (Binary) - Returns a base64 encoded string in binary format. // @returns data (Binary) - Returns a base64 encoded string in binary format.
func Download(_ context.Context, args ...core.Value) (core.Value, error) { func Download(_ context.Context, args ...core.Value) (core.Value, error) {

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// GetElement finds an element by a given CSS selector. // ELEMENT finds an element by a given CSS selector.
// Returns NONE if element not found. // Returns NONE if element not found.
// @param docOrEl (HTMLDocument|HTMLElement) - Parent document or element. // @param docOrEl (HTMLDocument|HTMLElement) - Parent document or element.
// @param selector (String) - CSS selector. // @param selector (String) - CSS selector.

View File

@ -7,7 +7,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// ElementExists returns a boolean value indicating whether there is an element matched by selector. // ELEMENT_EXISTS returns a boolean value indicating whether there is an element matched by selector.
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. // @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
// @param selector (String) - CSS selector. // @param selector (String) - CSS selector.
// @returns (Boolean) - A boolean value indicating whether there is an element matched by selector. // @returns (Boolean) - A boolean value indicating whether there is an element matched by selector.

View File

@ -7,7 +7,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// Elements finds HTML elements by a given CSS selector. // ELEMENTS finds HTML elements by a given CSS selector.
// Returns an empty array if element not found. // Returns an empty array if element not found.
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. // @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
// @param selector (String) - CSS selector. // @param selector (String) - CSS selector.

View File

@ -7,7 +7,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// ElementsCount returns a number of found HTML elements by a given CSS selector. // ELEMENTS_COUNT returns a number of found HTML elements by a given CSS selector.
// Returns an empty array if element not found. // Returns an empty array if element not found.
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. // @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
// @param selector (String) - CSS selector. // @param selector (String) - CSS selector.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// GetInnerHTML Returns inner HTML string of a given or matched by CSS selector element // INNER_HTML returns inner HTML string of a given or matched by CSS selector element
// @param doc (Open|GetElement) - Parent document or element. // @param doc (Open|GetElement) - Parent document or element.
// @param selector (String, optional) - String of CSS selector. // @param selector (String, optional) - String of CSS selector.
// @returns (String) - Inner HTML string if an element found, otherwise empty string. // @returns (String) - Inner HTML string if an element found, otherwise empty string.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// GetInnerHTMLAll returns an array of inner HTML strings of matched elements. // INNER_HTML_ALL returns an array of inner HTML strings of matched elements.
// @param doc (HTMLDocument|HTMLElement) - Parent document or element. // @param doc (HTMLDocument|HTMLElement) - Parent document or element.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.
// @returns (String) - An array of inner HTML strings if any element found, otherwise empty array. // @returns (String) - An array of inner HTML strings if any element found, otherwise empty array.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// GetInnerText returns inner text string of a given or matched by CSS selector element // INNER_TEXT returns inner text string of a given or matched by CSS selector element
// @param doc (HTMLDocument|HTMLElement) - Parent document or element. // @param doc (HTMLDocument|HTMLElement) - Parent document or element.
// @param selector (String, optional) - String of CSS selector. // @param selector (String, optional) - String of CSS selector.
// @returns (String) - Inner text if an element found, otherwise empty string. // @returns (String) - Inner text if an element found, otherwise empty string.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// GetInnerTextAll returns an array of inner text of matched elements. // INNER_TEXT_ALL returns an array of inner text of matched elements.
// @param doc (HTMLDocument|HTMLElement) - Parent document or element. // @param doc (HTMLDocument|HTMLElement) - Parent document or element.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.
// @returns (String) - An array of inner text if any element found, otherwise empty array. // @returns (String) - An array of inner text if any element found, otherwise empty array.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Hover fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to hover over the center of the element. // HOVER fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to hover over the center of the element.
// If there's no element matching selector, the method returns an error. // If there's no element matching selector, the method returns an error.
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. // @param docOrEl (HTMLDocument|HTMLElement) - Target document or element.
// @param selector (String, options) - If document is passed, this param must represent an element selector. // @param selector (String, options) - If document is passed, this param must represent an element selector.

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Input types a value to an underlying input element. // INPUT types a value to an underlying input element.
// @param source (HTMLPage | HTMLDocument | HTMLElement) - Event target. // @param source (HTMLPage | HTMLDocument | HTMLElement) - Event target.
// @param valueOrSelector (String) - Selector or a value. // @param valueOrSelector (String) - Selector or a value.
// @param value (String) - Target value. // @param value (String) - Target value.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// MouseMoveXY moves mouse by given coordinates. // MOUSE moves mouse by given coordinates.
// @param doc (HTMLDocument) - HTML document. // @param doc (HTMLDocument) - HTML document.
// @param x (Int|Float) - X coordinate. // @param x (Int|Float) - X coordinate.
// @param y (Int|Float) - Y coordinate. // @param y (Int|Float) - Y coordinate.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Navigate navigates a given page to a new resource. // NAVIGATE navigates a given page to a new resource.
// The operation blocks the execution until the page gets loaded. // The operation blocks the execution until the page gets loaded.
// Which means there is no need in WAIT_NAVIGATION function. // Which means there is no need in WAIT_NAVIGATION function.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// NavigateBack navigates a given page back within its navigation history. // NAVIGATE_BACK navigates a given page back within its navigation history.
// The operation blocks the execution until the page gets loaded. // The operation blocks the execution until the page gets loaded.
// If the history is empty, the function returns FALSE. // If the history is empty, the function returns FALSE.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// NavigateForward navigates a given page forward within its navigation history. // NAVIGATE_FORWARD navigates a given page forward within its navigation history.
// The operation blocks the execution until the page gets loaded. // The operation blocks the execution until the page gets loaded.
// If the history is empty, the function returns FALSE. // If the history is empty, the function returns FALSE.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Pagination creates an iterator that goes through pages using CSS selector. // PAGINATION creates an iterator that goes through pages using CSS selector.
// The iterator starts from the current page i.e. it does not change the page on 1st iteration. // The iterator starts from the current page i.e. it does not change the page on 1st iteration.
// That allows you to keep scraping logic inside FOR loop. // That allows you to keep scraping logic inside FOR loop.
// @param doc (Open) - Target document. // @param doc (Open) - Target document.

View File

@ -21,7 +21,7 @@ func ValidatePageRanges(pageRanges string) (bool, error) {
return match, nil return match, nil
} }
// PDF print a PDF of the current page. // PDF prints a PDF of the current page.
// @param target (HTMLPage|String) - Target page or url. // @param target (HTMLPage|String) - Target page or url.
// @param params (Object) - Optional, An object containing the following properties : // @param params (Object) - Optional, An object containing the following properties :
// Landscape (Bool) - Paper orientation. Defaults to false. // Landscape (Bool) - Paper orientation. Defaults to false.

View File

@ -10,7 +10,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// Screenshot takes a screenshot of a given page. // SCREENSHOT takes a screenshot of a given page.
// @param target (HTMLPage|String) - Target page or url. // @param target (HTMLPage|String) - Target page or url.
// @param params (Object) - Optional, An object containing the following properties : // @param params (Object) - Optional, An object containing the following properties :
// x (Float|Int) - Optional, X position of the viewport. // x (Float|Int) - Optional, X position of the viewport.

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// ScrollTop scrolls the document's window to its bottom. // SCROLL_BOTTOM scrolls the document's window to its bottom.
// @param doc (HTMLDocument) - Target document. // @param doc (HTMLDocument) - Target document.
func ScrollBottom(ctx context.Context, args ...core.Value) (core.Value, error) { func ScrollBottom(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1) err := core.ValidateArgs(args, 1, 1)

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// ScrollInto scrolls an element on. // SCROLL_ELEMENT scrolls an element on.
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. // @param docOrEl (HTMLDocument|HTMLElement) - Target document or element.
// @param selector (String, options) - If document is passed, this param must represent an element selector. // @param selector (String, options) - If document is passed, this param must represent an element selector.
func ScrollInto(ctx context.Context, args ...core.Value) (core.Value, error) { func ScrollInto(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// ScrollTop scrolls the document's window to its top. // SCROLL_TOP scrolls the document's window to its top.
// @param doc (HTMLDocument) - Target document. // @param doc (HTMLDocument) - Target document.
func ScrollTop(ctx context.Context, args ...core.Value) (core.Value, error) { func ScrollTop(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1) err := core.ValidateArgs(args, 1, 1)

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// ScrollXY scrolls by given coordinates. // SCROLL scrolls by given coordinates.
// @param doc (HTMLDocument) - HTML document. // @param doc (HTMLDocument) - HTML document.
// @param x (Int|Float) - X coordinate. // @param x (Int|Float) - X coordinate.
// @param y (Int|Float) - Y coordinate. // @param y (Int|Float) - Y coordinate.

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// Select selects a value from an underlying select element. // SELECT selects a value from an underlying select element.
// @param source (Open | GetElement) - Event target. // @param source (Open | GetElement) - Event target.
// @param valueOrSelector (String | Array<String>) - Selector or a an array of strings as a value. // @param valueOrSelector (String | Array<String>) - Selector or a an array of strings as a value.
// @param value (Array<String) - Target value. Optional. // @param value (Array<String) - Target value. Optional.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// SetInnerHTML sets inner HTML string to a given or matched by CSS selector element // INNER_HTML_SET sets inner HTML string to a given or matched by CSS selector element
// @param doc (Open|GetElement) - Parent document or element. // @param doc (Open|GetElement) - Parent document or element.
// @param selector (String, optional) - String of CSS selector. // @param selector (String, optional) - String of CSS selector.
// @param innerHTML (String) - String of inner HTML. // @param innerHTML (String) - String of inner HTML.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// SetInnerText sets inner text string to a given or matched by CSS selector element // INNER_TEXT_SET sets inner text string to a given or matched by CSS selector element
// @param doc (Open|GetElement) - Parent document or element. // @param doc (Open|GetElement) - Parent document or element.
// @param selector (String, optional) - String of CSS selector. // @param selector (String, optional) - String of CSS selector.
// @param innerText (String) - String of inner text. // @param innerText (String) - String of inner text.

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// StyleGet gets single or more style attribute value(s) of a given element. // STYLE_GET gets single or more style attribute value(s) of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param names (...String) - Style name(s). // @param names (...String) - Style name(s).
// @returns Object - Key-value pairs of style values. // @returns Object - Key-value pairs of style values.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// StyleRemove removes single or more style attribute value(s) of a given element. // STYLE_REMOVE removes single or more style attribute value(s) of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param names (...String) - Style name(s). // @param names (...String) - Style name(s).
func StyleRemove(ctx context.Context, args ...core.Value) (core.Value, error) { func StyleRemove(ctx context.Context, args ...core.Value) (core.Value, error) {

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// StyleSet sets or updates a single or more style attribute value of a given element. // STYLE_SET sets or updates a single or more style attribute value of a given element.
// @param el (HTMLElement) - Target element. // @param el (HTMLElement) - Target element.
// @param nameOrObj (String | Object) - Style name or an object representing a key-value pair of attributes. // @param nameOrObj (String | Object) - Style name or an object representing a key-value pair of attributes.
// @param value (String) - If a second parameter is a string value, this parameter represent a style value. // @param value (String) - If a second parameter is a string value, this parameter represent a style value.

View File

@ -9,10 +9,22 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WAIT_ATTR waits until a target attribute's value appears
// @param node (HTMLPage | HTMLDocument | HTMLElement) - Parent document.
// @param attrNameOrSelector (String) - String of an attr name or CSS selector.
// @param attrValueOrAttrName (String | Any) - Attr value or name.
// @param attrValueOrTimeout (Any | Int, optional) - Attr value or an optional timeout.
// @param timeout (Int, optional) - Optional timeout.
func WaitAttribute(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitAttribute(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitAttributeWhen(ctx, args, drivers.WaitEventPresence) return waitAttributeWhen(ctx, args, drivers.WaitEventPresence)
} }
// WAIT_NO_ATTR waits until a target attribute's value disappears
// @param node (HTMLPage | HTMLDocument | HTMLElement) - Parent document.
// @param attrNameOrSelector (String) - String of an attr name or CSS selector.
// @param attrValueOrAttrName (String | Any) - Attr value or name.
// @param attrValueOrTimeout (Any | Int, optional) - Attr value or an optional timeout.
// @param timeout (Int, optional) - Optional timeout.
func WaitNoAttribute(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitNoAttribute(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitAttributeWhen(ctx, args, drivers.WaitEventAbsence) return waitAttributeWhen(ctx, args, drivers.WaitEventAbsence)
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WaitClassAll waits for a class to appear on all matched elements. // WAIT_ATTR_ALL waits for an attribute to appear on all matched elements with a given value.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param doc (HTMLDocument) - Parent document. // @param doc (HTMLDocument) - Parent document.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.
@ -19,7 +19,7 @@ func WaitAttributeAll(ctx context.Context, args ...core.Value) (core.Value, erro
return waitAttributeAllWhen(ctx, args, drivers.WaitEventPresence) return waitAttributeAllWhen(ctx, args, drivers.WaitEventPresence)
} }
// WaitClassAll waits for a class to disappear on all matched elements. // WAIT_NO_ATTR_ALL waits for an attribute to disappear on all matched elements by a given value.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param doc (HTMLDocument) - Parent document. // @param doc (HTMLDocument) - Parent document.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.

View File

@ -9,9 +9,9 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WaitClass waits for a class to appear on a given element. // WAIT_CLASS waits for a class to appear on a given element.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. // @param node (HTMLPage | HTMLDocument | HTMLElement) - Target node.
// @param selectorOrClass (String) - If document is passed, this param must represent an element selector. // @param selectorOrClass (String) - If document is passed, this param must represent an element selector.
// Otherwise target class. // Otherwise target class.
// @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name. // @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name.
@ -22,9 +22,9 @@ func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassWhen(ctx, args, drivers.WaitEventPresence) return waitClassWhen(ctx, args, drivers.WaitEventPresence)
} }
// WaitClass waits for a class to disappear on a given element. // WAIT_NO_CLASS waits for a class to disappear on a given element.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. // @param node (HTMLPage | HTMLDocument | HTMLElement) - Target node.
// @param selectorOrClass (String) - If document is passed, this param must represent an element selector. // @param selectorOrClass (String) - If document is passed, this param must represent an element selector.
// Otherwise target class. // Otherwise target class.
// @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name. // @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WaitClassAll waits for a class to appear on all matched elements. // WAIT_CLASS_ALL waits for a class to appear on all matched elements.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param doc (HTMLDocument) - Parent document. // @param doc (HTMLDocument) - Parent document.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.
@ -19,7 +19,7 @@ func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassAllWhen(ctx, args, drivers.WaitEventPresence) return waitClassAllWhen(ctx, args, drivers.WaitEventPresence)
} }
// WaitClassAll waits for a class to disappear on all matched elements. // WAIT_NO_CLASS_ALL waits for a class to disappear on all matched elements.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param doc (HTMLDocument) - Parent document. // @param doc (HTMLDocument) - Parent document.
// @param selector (String) - String of CSS selector. // @param selector (String) - String of CSS selector.

View File

@ -9,16 +9,16 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WaitElement waits for element to appear in the DOM. // WAIT_ELEMENT waits for element to appear in the DOM.
// Stops the execution until it finds an element or operation times out. // Stops the execution until it finds an element or operation times out.
// @param doc (HTMLDocument) - Driver HTMLDocument. // @param n (HTMLDocument) - Driver HTMLDocument.
// @param selector (String) - Target element's selector. // @param selector (String) - Target element's selector.
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms. // @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitElementWhen(ctx, args, drivers.WaitEventPresence) return waitElementWhen(ctx, args, drivers.WaitEventPresence)
} }
// WaitNoElements waits for element to disappear in the DOM. // WAIT_NO_ELEMENT waits for element to disappear in the DOM.
// Stops the execution until it does not find an element or operation times out. // Stops the execution until it does not find an element or operation times out.
// @param doc (HTMLDocument) - Driver HTMLDocument. // @param doc (HTMLDocument) - Driver HTMLDocument.
// @param selector (String) - Target element's selector. // @param selector (String) - Target element's selector.

View File

@ -9,7 +9,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WaitNavigation waits for a given page to navigate to a new url. // WAIT_NAVIGATION waits for a given page to navigate to a new url.
// Stops the execution until the navigation ends or operation times out. // Stops the execution until the navigation ends or operation times out.
// @param page (HTMLPage) - Target page. // @param page (HTMLPage) - Target page.
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms. // @param timeout (Int, optional) - Optional timeout. Default 5000 ms.

View File

@ -9,10 +9,12 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WAIT_STYLE
func WaitStyle(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitStyle(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleWhen(ctx, args, drivers.WaitEventPresence) return waitStyleWhen(ctx, args, drivers.WaitEventPresence)
} }
// WAIT_NO_STYLE
func WaitNoStyle(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitNoStyle(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleWhen(ctx, args, drivers.WaitEventAbsence) return waitStyleWhen(ctx, args, drivers.WaitEventAbsence)
} }

View File

@ -9,10 +9,12 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types" "github.com/MontFerret/ferret/pkg/runtime/values/types"
) )
// WAIT_STYLE_ALL
func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleAllWhen(ctx, args, drivers.WaitEventPresence) return waitStyleAllWhen(ctx, args, drivers.WaitEventPresence)
} }
// WAIT_NO_STYLE_ALL
func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) { func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitStyleAllWhen(ctx, args, drivers.WaitEventAbsence) return waitStyleAllWhen(ctx, args, drivers.WaitEventAbsence)
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
) )
// XPath evaluates the XPath expression. // XPATH evaluates the XPath expression.
// @param source (HTMLPage | HTMLDocument | HTMLElement) - Target HTML object. // @param source (HTMLPage | HTMLDocument | HTMLElement) - Target HTML object.
// @param expression (String) - XPath expression. // @param expression (String) - XPath expression.
// @returns (Value) - Returns result of a given XPath expression. // @returns (Value) - Returns result of a given XPath expression.