feat: add MouseDown/MouseUp methods to InteractiveBrowser
Enables drag operations (mousedown → mousemove → mouseup) needed for slider captchas and other drag-based interactions. Closes #79 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,10 @@ type InteractiveBrowser interface {
|
||||
|
||||
// MouseClick clicks at the given coordinates with the specified button ("left", "middle", "right").
|
||||
MouseClick(x, y float64, button string) error
|
||||
// MouseDown presses the mouse button at the given coordinates without releasing.
|
||||
MouseDown(x, y float64, button string) error
|
||||
// MouseUp releases the mouse button at the given coordinates.
|
||||
MouseUp(x, y float64, button string) error
|
||||
// MouseMove moves the mouse to the given coordinates.
|
||||
MouseMove(x, y float64) error
|
||||
// MouseWheel scrolls by the given delta.
|
||||
@@ -156,6 +160,38 @@ func (ib *interactiveBrowser) MouseClick(x, y float64, button string) error {
|
||||
return ib.page.Mouse().Click(x, y, playwright.MouseClickOptions{Button: btn})
|
||||
}
|
||||
|
||||
func (ib *interactiveBrowser) MouseDown(x, y float64, button string) error {
|
||||
if err := ib.page.Mouse().Move(x, y); err != nil {
|
||||
return err
|
||||
}
|
||||
var btn *playwright.MouseButton
|
||||
switch button {
|
||||
case "right":
|
||||
btn = playwright.MouseButtonRight
|
||||
case "middle":
|
||||
btn = playwright.MouseButtonMiddle
|
||||
default:
|
||||
btn = playwright.MouseButtonLeft
|
||||
}
|
||||
return ib.page.Mouse().Down(playwright.MouseDownOptions{Button: btn})
|
||||
}
|
||||
|
||||
func (ib *interactiveBrowser) MouseUp(x, y float64, button string) error {
|
||||
if err := ib.page.Mouse().Move(x, y); err != nil {
|
||||
return err
|
||||
}
|
||||
var btn *playwright.MouseButton
|
||||
switch button {
|
||||
case "right":
|
||||
btn = playwright.MouseButtonRight
|
||||
case "middle":
|
||||
btn = playwright.MouseButtonMiddle
|
||||
default:
|
||||
btn = playwright.MouseButtonLeft
|
||||
}
|
||||
return ib.page.Mouse().Up(playwright.MouseUpOptions{Button: btn})
|
||||
}
|
||||
|
||||
func (ib *interactiveBrowser) MouseMove(x, y float64) error {
|
||||
return ib.page.Mouse().Move(x, y)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user