diff --git a/interactive.go b/interactive.go index aad8558..8929a8f 100644 --- a/interactive.go +++ b/interactive.go @@ -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) } diff --git a/promote_test.go b/promote_test.go index 88a8b9d..3e60725 100644 --- a/promote_test.go +++ b/promote_test.go @@ -13,7 +13,9 @@ func (m mockInteractiveBrowser) GoBack() (string, error) { return func (m mockInteractiveBrowser) GoForward() (string, error) { return "", nil } func (m mockInteractiveBrowser) URL() string { return "" } func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil } -func (m mockInteractiveBrowser) MouseMove(float64, float64) error { return nil } +func (m mockInteractiveBrowser) MouseDown(float64, float64, string) error { return nil } +func (m mockInteractiveBrowser) MouseUp(float64, float64, string) error { return nil } +func (m mockInteractiveBrowser) MouseMove(float64, float64) error { return nil } func (m mockInteractiveBrowser) MouseWheel(float64, float64) error { return nil } func (m mockInteractiveBrowser) KeyboardType(string) error { return nil } func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil }