feat(driver): add EraseText to the device driver surface

This commit is contained in:
pj committed 2026-06-05 17:40:09 +05:30
1 parent 72055e5d9f
commit 41511a2a32
4 files changed
+49 -13

No files matched your search

+17
View File
@@ -193,6 +193,23 @@ func (d *Driver) InputText(_ context.Context, text string) error {
)
}
// EraseText clears the focused field. InputText above already replaces via
// select-all, so the character count is not needed to bound the deletion.
func (d *Driver) EraseText(_ context.Context, _ int) error {
return chromedp.Run(d.tabCtx,
chromedp.ActionFunc(func(ctx context.Context) error {
if err := chromedp.Evaluate(`
(function() {
const el = document.activeElement;
if (el && typeof el.select === 'function') el.select();
})()`, nil).Do(ctx); err != nil {
return err
}
return input.InsertText("").Do(ctx)
}),
)
}
func (d *Driver) Swipe(_ context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
millis := max(duration.Milliseconds(), 50)
script := fmt.Sprintf(`