-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add the MouseMoveNode function #787
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,28 @@ func MouseEvent(typ input.MouseType, x, y float64, opts ...MouseOption) MouseAct | |
return p | ||
} | ||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra blank lines |
||
func MouseMoveXY(x, y float64, opts ...MouseOption) MouseAction { | ||
return ActionFunc(func(ctx context.Context) error { | ||
p := &input.DispatchMouseEventParams{ | ||
Type: input.MouseMoved, | ||
X: x, | ||
Y: y, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to use the constructor func? p := input.DispatchMouseEvent(input.MouseMoved, x, y) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I just noticed this function here, it did the thing what I’m looking for for MouseMoveXY |
||
|
||
// apply opts | ||
for _, o := range opts { | ||
p = o(p) | ||
} | ||
|
||
return p.Do(ctx) | ||
}) | ||
} | ||
|
||
|
||
// MouseClickXY is an action that sends a left mouse button click (ie, | ||
// mousePressed and mouseReleased event) to the X, Y location. | ||
func MouseClickXY(x, y float64, opts ...MouseOption) MouseAction { | ||
|
@@ -49,6 +71,38 @@ func MouseClickXY(x, y float64, opts ...MouseOption) MouseAction { | |
}) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra blank lines |
||
func MouseMoveNode(n *cdp.Node, opts ...MouseOption) MouseAction { | ||
return ActionFunc(func(ctx context.Context) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The MouseMoveNode function is the similar function to the MouseClickNode, but it doesn’t do the click movement, just put the mouse on the target node. |
||
boxes, err := dom.GetContentQuads().WithNodeID(n.NodeID).Do(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
content := boxes[0] | ||
|
||
c := len(content) | ||
if c%2 != 0 || c < 1 { | ||
return ErrInvalidDimensions | ||
} | ||
|
||
var x, y float64 | ||
for i := 0; i < c; i += 2 { | ||
x += content[i] | ||
y += content[i+1] | ||
} | ||
x /= float64(c / 2) | ||
y /= float64(c / 2) | ||
|
||
return MouseMoveXY(x, y, opts...).Do(ctx) | ||
}) | ||
} | ||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra blank lines above. |
||
// MouseClickNode is an action that dispatches a mouse left button click event | ||
// at the center of a specified node. | ||
// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra blank lines