mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
Merge pull request #380 from MontFerret/refactoring/html-element
Removed redundant element value caching
This commit is contained in:
commit
df390a629a
@ -268,7 +268,7 @@ func (doc *HTMLDocument) ExistsBySelector(ctx context.Context, selector values.S
|
||||
}
|
||||
|
||||
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 {
|
||||
doc.logError(errors.Wrap(err, "failed to read document title"))
|
||||
|
@ -10,6 +10,13 @@ import (
|
||||
"sync"
|
||||
"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/cdp/eval"
|
||||
"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/values"
|
||||
"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)
|
||||
|
||||
type (
|
||||
HTMLElementIdentity struct {
|
||||
nodeID dom.NodeID
|
||||
objectID runtime.RemoteObjectID
|
||||
NodeID dom.NodeID
|
||||
ObjectID runtime.RemoteObjectID
|
||||
}
|
||||
|
||||
HTMLElement struct {
|
||||
@ -49,7 +49,6 @@ type (
|
||||
nodeName values.String
|
||||
innerHTML *common.LazyValue
|
||||
innerText *common.LazyValue
|
||||
value core.Value
|
||||
attributes *common.LazyValue
|
||||
style *common.LazyValue
|
||||
children []HTMLElementIdentity
|
||||
@ -83,10 +82,6 @@ func LoadHTMLElement(
|
||||
return nil, core.Error(core.ErrNotFound, fmt.Sprintf("element %d", nodeID))
|
||||
}
|
||||
|
||||
id := HTMLElementIdentity{}
|
||||
id.nodeID = nodeID
|
||||
id.objectID = *obj.Object.ObjectID
|
||||
|
||||
return LoadHTMLElementWithID(
|
||||
ctx,
|
||||
logger,
|
||||
@ -94,7 +89,10 @@ func LoadHTMLElement(
|
||||
broker,
|
||||
input,
|
||||
exec,
|
||||
id,
|
||||
HTMLElementIdentity{
|
||||
NodeID: nodeID,
|
||||
ObjectID: *obj.Object.ObjectID,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@ -111,18 +109,12 @@ func LoadHTMLElementWithID(
|
||||
ctx,
|
||||
dom.
|
||||
NewDescribeNodeArgs().
|
||||
SetObjectID(id.objectID).
|
||||
SetObjectID(id.ObjectID).
|
||||
SetDepth(1),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, core.Error(err, strconv.Itoa(int(id.nodeID)))
|
||||
}
|
||||
|
||||
var val string
|
||||
|
||||
if node.Node.Value != nil {
|
||||
val = *node.Node.Value
|
||||
return nil, core.Error(err, strconv.Itoa(int(id.NodeID)))
|
||||
}
|
||||
|
||||
return NewHTMLElement(
|
||||
@ -134,7 +126,6 @@ func LoadHTMLElementWithID(
|
||||
id,
|
||||
node.Node.NodeType,
|
||||
node.Node.NodeName,
|
||||
val,
|
||||
createChildrenArray(node.Node.Children),
|
||||
), nil
|
||||
}
|
||||
@ -148,7 +139,6 @@ func NewHTMLElement(
|
||||
id HTMLElementIdentity,
|
||||
nodeType int,
|
||||
nodeName string,
|
||||
value string,
|
||||
children []HTMLElementIdentity,
|
||||
) *HTMLElement {
|
||||
el := new(HTMLElement)
|
||||
@ -165,9 +155,7 @@ func NewHTMLElement(
|
||||
el.innerText = common.NewLazyValue(el.loadInnerText)
|
||||
el.attributes = common.NewLazyValue(el.loadAttrs)
|
||||
el.style = common.NewLazyValue(el.parseStyle)
|
||||
el.value = values.EmptyString
|
||||
el.loadedChildren = common.NewLazyValue(el.loadChildren)
|
||||
el.value = values.NewString(value)
|
||||
el.children = children
|
||||
|
||||
broker.AddEventListener(events.EventReload, el.handlePageReload)
|
||||
@ -243,7 +231,7 @@ func (el *HTMLElement) Hash() uint64 {
|
||||
|
||||
h.Write([]byte(el.Type().String()))
|
||||
h.Write([]byte(":"))
|
||||
h.Write([]byte(strconv.Itoa(int(el.id.nodeID))))
|
||||
h.Write([]byte(strconv.Itoa(int(el.id.NodeID))))
|
||||
|
||||
return h.Sum64()
|
||||
}
|
||||
@ -269,15 +257,7 @@ func (el *HTMLElement) GetValue(ctx context.Context) (core.Value, error) {
|
||||
return values.None, drivers.ErrDetached
|
||||
}
|
||||
|
||||
val, err := el.exec.ReadProperty(ctx, el.id.objectID, "value")
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
el.value = val
|
||||
|
||||
return val, nil
|
||||
return el.exec.ReadProperty(ctx, el.id.ObjectID, "value")
|
||||
}
|
||||
|
||||
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 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 {
|
||||
@ -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 {
|
||||
return el.client.DOM.SetAttributeValue(
|
||||
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 {
|
||||
err := el.client.DOM.RemoveAttribute(
|
||||
ctx,
|
||||
dom.NewRemoveAttributeArgs(el.id.nodeID, name.String()),
|
||||
dom.NewRemoveAttributeArgs(el.id.NodeID, name.String()),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@ -481,7 +461,7 @@ func (el *HTMLElement) QuerySelector(ctx context.Context, selector values.String
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
@ -506,7 +486,7 @@ func (el *HTMLElement) QuerySelectorAll(ctx context.Context, selector values.Str
|
||||
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)
|
||||
|
||||
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(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: json.RawMessage(exp),
|
||||
@ -633,8 +613,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
|
||||
el.input,
|
||||
el.exec,
|
||||
HTMLElementIdentity{
|
||||
nodeID: repl.NodeID,
|
||||
objectID: *descr.Value.ObjectID,
|
||||
NodeID: repl.NodeID,
|
||||
ObjectID: *descr.Value.ObjectID,
|
||||
},
|
||||
)
|
||||
|
||||
@ -665,8 +645,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
|
||||
el.input,
|
||||
el.exec,
|
||||
HTMLElementIdentity{
|
||||
nodeID: repl.NodeID,
|
||||
objectID: *out.ObjectID,
|
||||
NodeID: repl.NodeID,
|
||||
ObjectID: *out.ObjectID,
|
||||
},
|
||||
)
|
||||
default:
|
||||
@ -713,7 +693,7 @@ func (el *HTMLElement) GetInnerTextBySelector(ctx context.Context, selector valu
|
||||
ctx,
|
||||
templates.GetInnerTextBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -748,7 +728,7 @@ func (el *HTMLElement) SetInnerTextBySelector(ctx context.Context, selector, inn
|
||||
ctx,
|
||||
templates.SetInnerTextBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -774,7 +754,7 @@ func (el *HTMLElement) GetInnerTextBySelectorAll(ctx context.Context, selector v
|
||||
ctx,
|
||||
templates.GetInnerTextBySelectorAll(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -833,7 +813,7 @@ func (el *HTMLElement) GetInnerHTMLBySelector(ctx context.Context, selector valu
|
||||
ctx,
|
||||
templates.GetInnerHTMLBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -868,7 +848,7 @@ func (el *HTMLElement) SetInnerHTMLBySelector(ctx context.Context, selector, inn
|
||||
ctx,
|
||||
templates.SetInnerHTMLBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -894,7 +874,7 @@ func (el *HTMLElement) GetInnerHTMLBySelectorAll(ctx context.Context, selector v
|
||||
ctx,
|
||||
templates.GetInnerHTMLBySelectorAll(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
ObjectID: &el.id.ObjectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
@ -919,7 +899,7 @@ func (el *HTMLElement) CountBySelector(ctx context.Context, selector values.Stri
|
||||
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)
|
||||
|
||||
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?
|
||||
selectorArgs := dom.NewQuerySelectorArgs(el.id.nodeID, selector.String())
|
||||
selectorArgs := dom.NewQuerySelectorArgs(el.id.NodeID, selector.String())
|
||||
res, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
@ -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 el.input.Type(ctx, el.id.objectID, input.TypeParams{
|
||||
return el.input.Type(ctx, el.id.ObjectID, input.TypeParams{
|
||||
Text: value.String(),
|
||||
Clear: false,
|
||||
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 {
|
||||
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(),
|
||||
Clear: false,
|
||||
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 {
|
||||
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 {
|
||||
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) {
|
||||
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) {
|
||||
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 {
|
||||
return el.input.ScrollIntoView(ctx, el.id.objectID)
|
||||
return el.input.ScrollIntoView(ctx, el.id.ObjectID)
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
@ -1095,11 +1075,11 @@ func (el *HTMLElement) BlurBySelector(ctx context.Context, selector values.Strin
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
@ -1154,7 +1134,7 @@ func (el *HTMLElement) loadInnerText(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 {
|
||||
return values.None, err
|
||||
@ -1178,7 +1158,7 @@ func (el *HTMLElement) loadChildren(ctx context.Context) (core.Value, error) {
|
||||
el.events,
|
||||
el.input,
|
||||
el.exec,
|
||||
childID.nodeID,
|
||||
childID.NodeID,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@ -1224,7 +1204,7 @@ func (el *HTMLElement) handleAttrModified(ctx context.Context, message interface
|
||||
}
|
||||
|
||||
// it's not for this el
|
||||
if reply.NodeID != el.id.nodeID {
|
||||
if reply.NodeID != el.id.NodeID {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1268,7 +1248,7 @@ func (el *HTMLElement) handleAttrRemoved(ctx context.Context, message interface{
|
||||
}
|
||||
|
||||
// it's not for this el
|
||||
if reply.NodeID != el.id.nodeID {
|
||||
if reply.NodeID != el.id.NodeID {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1310,7 +1290,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
|
||||
return
|
||||
}
|
||||
|
||||
if reply.NodeID != el.id.nodeID {
|
||||
if reply.NodeID != el.id.NodeID {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1323,7 +1303,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
|
||||
|
||||
node, err := el.client.DOM.DescribeNode(
|
||||
ctx,
|
||||
dom.NewDescribeNodeArgs().SetObjectID(el.id.objectID),
|
||||
dom.NewDescribeNodeArgs().SetObjectID(el.id.ObjectID),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@ -1342,7 +1322,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
||||
return
|
||||
}
|
||||
|
||||
if reply.ParentNodeID != el.id.nodeID {
|
||||
if reply.ParentNodeID != el.id.NodeID {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1358,7 +1338,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
||||
defer el.mu.Unlock()
|
||||
|
||||
for idx, id := range el.children {
|
||||
if id.nodeID == prevID {
|
||||
if id.NodeID == prevID {
|
||||
targetIDx = idx
|
||||
break
|
||||
}
|
||||
@ -1369,7 +1349,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
||||
}
|
||||
|
||||
nextIdentity := HTMLElementIdentity{
|
||||
nodeID: reply.Node.NodeID,
|
||||
NodeID: reply.Node.NodeID,
|
||||
}
|
||||
|
||||
arr := el.children
|
||||
@ -1403,7 +1383,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
||||
return
|
||||
}
|
||||
|
||||
if reply.ParentNodeID != el.id.nodeID {
|
||||
if reply.ParentNodeID != el.id.NodeID {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1418,7 +1398,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
||||
defer el.mu.Unlock()
|
||||
|
||||
for idx, id := range el.children {
|
||||
if id.nodeID == targetID {
|
||||
if id.NodeID == targetID {
|
||||
targetIDx = idx
|
||||
break
|
||||
}
|
||||
@ -1440,7 +1420,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
||||
el.logger.Error().
|
||||
Timestamp().
|
||||
Err(err).
|
||||
Int("nodeID", int(el.id.nodeID)).
|
||||
Int("nodeID", int(el.id.NodeID)).
|
||||
Msg("failed to update element")
|
||||
|
||||
return
|
||||
@ -1458,7 +1438,7 @@ func (el *HTMLElement) logError(err error) *zerolog.Event {
|
||||
return el.logger.
|
||||
Error().
|
||||
Timestamp().
|
||||
Int("nodeID", int(el.id.nodeID)).
|
||||
Str("objectID", string(el.id.objectID)).
|
||||
Int("nodeID", int(el.id.NodeID)).
|
||||
Str("objectID", string(el.id.ObjectID)).
|
||||
Err(err)
|
||||
}
|
||||
|
@ -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 {
|
||||
var objID *runtime.RemoteObjectID
|
||||
|
||||
if id.objectID != "" {
|
||||
objID = &id.objectID
|
||||
if id.ObjectID != "" {
|
||||
objID = &id.ObjectID
|
||||
} 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 {
|
||||
return err
|
||||
@ -110,10 +110,10 @@ func getInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
|
||||
if nodeType != html.DocumentNode {
|
||||
var objID runtime.RemoteObjectID
|
||||
|
||||
if id.objectID != "" {
|
||||
objID = id.objectID
|
||||
if id.ObjectID != "" {
|
||||
objID = id.ObjectID
|
||||
} 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 {
|
||||
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 {
|
||||
var objID *runtime.RemoteObjectID
|
||||
|
||||
if id.objectID != "" {
|
||||
objID = &id.objectID
|
||||
if id.ObjectID != "" {
|
||||
objID = &id.ObjectID
|
||||
} 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 {
|
||||
return err
|
||||
@ -186,10 +186,10 @@ func getInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
|
||||
if nodeType != html.DocumentNode {
|
||||
var objID runtime.RemoteObjectID
|
||||
|
||||
if id.objectID != "" {
|
||||
objID = id.objectID
|
||||
if id.ObjectID != "" {
|
||||
objID = id.ObjectID
|
||||
} 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 {
|
||||
return "", err
|
||||
@ -238,7 +238,7 @@ func createChildrenArray(nodes []dom.Node) []HTMLElementIdentity {
|
||||
for idx, child := range nodes {
|
||||
child := child
|
||||
children[idx] = HTMLElementIdentity{
|
||||
nodeID: child.NodeID,
|
||||
NodeID: child.NodeID,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 names (...String) - Attribute name(s).
|
||||
// @returns Object - Key-value pairs of attribute values.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 names (...String) - Attribute name(s).
|
||||
func AttributeRemove(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 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.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 selector (String, options) - Selector.
|
||||
func InputClear(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selectorOrCount (String | Int, optional) - Optional selector or count of clicks.
|
||||
// @param count (Int, optional) - Optional count of clicks.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String) - Selector.
|
||||
// @param count (Int, optional) - Optional count of clicks.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 cookie (...HTTPCookie|String) - Cookie or cookie name to delete.
|
||||
func CookieDel(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 name (String) - Cookie or cookie name to delete.
|
||||
func CookieGet(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 cookie... (HTTPCookie) - Target cookies.
|
||||
func CookieSet(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -18,7 +18,7 @@ type PageLoadParams struct {
|
||||
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.
|
||||
// @param params (Object) - Optional, An object containing the following properties :
|
||||
// driver (String) - Optional, driver name.
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"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.
|
||||
// @returns data (Binary) - Returns a base64 encoded string in binary format.
|
||||
func Download(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// @param docOrEl (HTMLDocument|HTMLElement) - Parent document or element.
|
||||
// @param selector (String) - CSS selector.
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"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 selector (String) - CSS selector.
|
||||
// @returns (Boolean) - A boolean value indicating whether there is an element matched by selector.
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"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.
|
||||
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
|
||||
// @param selector (String) - CSS selector.
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"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.
|
||||
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
|
||||
// @param selector (String) - CSS selector.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String, optional) - String of CSS selector.
|
||||
// @returns (String) - Inner HTML string if an element found, otherwise empty string.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String) - String of CSS selector.
|
||||
// @returns (String) - An array of inner HTML strings if any element found, otherwise empty array.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String, optional) - String of CSS selector.
|
||||
// @returns (String) - Inner text if an element found, otherwise empty string.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String) - String of CSS selector.
|
||||
// @returns (String) - An array of inner text if any element found, otherwise empty array.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element.
|
||||
// @param selector (String, options) - If document is passed, this param must represent an element selector.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 valueOrSelector (String) - Selector or a value.
|
||||
// @param value (String) - Target value.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 x (Int|Float) - X coordinate.
|
||||
// @param y (Int|Float) - Y coordinate.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// Which means there is no need in WAIT_NAVIGATION function.
|
||||
// @param page (HTMLPage) - Target page.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// If the history is empty, the function returns FALSE.
|
||||
// @param page (HTMLPage) - Target page.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// If the history is empty, the function returns FALSE.
|
||||
// @param page (HTMLPage) - Target page.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// That allows you to keep scraping logic inside FOR loop.
|
||||
// @param doc (Open) - Target document.
|
||||
|
@ -21,7 +21,7 @@ func ValidatePageRanges(pageRanges string) (bool, error) {
|
||||
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 params (Object) - Optional, An object containing the following properties :
|
||||
// Landscape (Bool) - Paper orientation. Defaults to false.
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"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 params (Object) - Optional, An object containing the following properties :
|
||||
// x (Float|Int) - Optional, X position of the viewport.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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.
|
||||
func ScrollBottom(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 1, 1)
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 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) {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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.
|
||||
func ScrollTop(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 1, 1)
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
)
|
||||
|
||||
// ScrollXY scrolls by given coordinates.
|
||||
// SCROLL scrolls by given coordinates.
|
||||
// @param doc (HTMLDocument) - HTML document.
|
||||
// @param x (Int|Float) - X coordinate.
|
||||
// @param y (Int|Float) - Y coordinate.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 valueOrSelector (String | Array<String>) - Selector or a an array of strings as a value.
|
||||
// @param value (Array<String) - Target value. Optional.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String, optional) - String of CSS selector.
|
||||
// @param innerHTML (String) - String of inner HTML.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 selector (String, optional) - String of CSS selector.
|
||||
// @param innerText (String) - String of inner text.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 names (...String) - Style name(s).
|
||||
// @returns Object - Key-value pairs of style values.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 names (...String) - Style name(s).
|
||||
func StyleRemove(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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 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.
|
||||
|
@ -9,10 +9,22 @@ import (
|
||||
"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) {
|
||||
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) {
|
||||
return waitAttributeWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// @param doc (HTMLDocument) - Parent document.
|
||||
// @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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// @param doc (HTMLDocument) - Parent document.
|
||||
// @param selector (String) - String of CSS selector.
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
"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.
|
||||
// @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.
|
||||
// Otherwise target class.
|
||||
// @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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// @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.
|
||||
// Otherwise target class.
|
||||
// @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// @param doc (HTMLDocument) - Parent document.
|
||||
// @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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// @param doc (HTMLDocument) - Parent document.
|
||||
// @param selector (String) - String of CSS selector.
|
||||
|
@ -9,16 +9,16 @@ import (
|
||||
"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.
|
||||
// @param doc (HTMLDocument) - Driver HTMLDocument.
|
||||
// @param n (HTMLDocument) - Driver HTMLDocument.
|
||||
// @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.
|
||||
// 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.
|
||||
// @param doc (HTMLDocument) - Driver HTMLDocument.
|
||||
// @param selector (String) - Target element's selector.
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"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.
|
||||
// @param page (HTMLPage) - Target page.
|
||||
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
|
||||
|
@ -9,10 +9,12 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
)
|
||||
|
||||
// WAIT_STYLE
|
||||
func WaitStyle(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitStyleWhen(ctx, args, drivers.WaitEventPresence)
|
||||
}
|
||||
|
||||
// WAIT_NO_STYLE
|
||||
func WaitNoStyle(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitStyleWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
)
|
||||
|
||||
// WAIT_STYLE_ALL
|
||||
func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitStyleAllWhen(ctx, args, drivers.WaitEventPresence)
|
||||
}
|
||||
|
||||
// WAIT_NO_STYLE_ALL
|
||||
func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return waitStyleAllWhen(ctx, args, drivers.WaitEventAbsence)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"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 expression (String) - XPath expression.
|
||||
// @returns (Value) - Returns result of a given XPath expression.
|
||||
|
Loading…
Reference in New Issue
Block a user