-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdom_action.go
More file actions
66 lines (52 loc) · 1.95 KB
/
Copy pathdom_action.go
File metadata and controls
66 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package chromy
import (
"context"
"github.com/mafredri/cdp/protocol/dom"
)
func WaitNode(selector string) Action {
return actionWrapper("waitNode", NewQuery(QuerySelector(selector)))
}
func WaitNodeAll(selector string) Action {
return actionWrapper("waitNodeAll", NewQuery(QuerySelectorAll(selector)))
}
func GetNode(selector string, node *Node) Action {
return actionWrapper("getNode", NewQuery(QuerySelector(selector), QueryNode(node)))
}
func GetNodeAll(selector string, nodes *[]*Node) Action {
return actionWrapper("getNodeAll", NewQuery(QuerySelectorAll(selector), QueryNodes(nodes)))
}
func OnNode(selector string, fn func(ctx context.Context, t *Target, node *Node) error) Action {
return actionWrapper("onNode", NewQuery(QuerySelector(selector), QueryAfter(fn)))
}
func OnNodeAll(selector string, fn func(ctx context.Context, t *Target, nodes ...*Node) error) Action {
return actionWrapper("onNodeAll", NewQuery(QuerySelectorAll(selector), QueryAfterAll(fn)))
}
func Focus(selector string) Action {
return actionWrapper("focus", OnNode(selector, func(ctx context.Context, t *Target, node *Node) error {
err := t.Client().DOM.Focus(ctx, dom.NewFocusArgs().SetNodeID(node.NodeID))
if err != nil {
return err
}
return nil
}))
}
func Blur(selector string) Action {
return actionWrapper("blur", OnNode(selector, func(ctx context.Context, t *Target, node *Node) error {
cli := t.Client()
objectID, err := nodeIDToRemoteObjectID(ctx, cli, node.NodeID)
if err != nil {
return err
}
return callFuncOnRemoteObject(ctx, cli, objectID, "function() { this.click() }", nil, nil)
}))
}
func Click(selector string) Action {
return actionWrapper("click", OnNode(selector, func(ctx context.Context, t *Target, node *Node) error {
cli := t.Client()
objectID, err := nodeIDToRemoteObjectID(ctx, cli, node.NodeID)
if err != nil {
return err
}
return callFuncOnRemoteObject(ctx, cli, objectID, "function() { this.click() }", nil, nil)
}))
}