Skip to content

Commit

Permalink
Add clear method on locator
Browse files Browse the repository at this point in the history
This is a new method on the locator type. It will clear the text from
an input element. It uses the existing fill API to override existing
text with an empty string.
  • Loading branch information
ankur22 committed Jan 10, 2024
1 parent a144bfd commit 27371aa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ func NewLocator(ctx context.Context, selector string, f *Frame, l *log.Logger) *
}
}

// Clear will clear the input field.
// This works with the Fill API and fills the input field with an empty string.
func (l *Locator) Clear(opts *FrameFillOptions) error {
l.log.Debugf(
"Locator:Clear", "fid:%s furl:%q sel:%q opts:%+v",
l.frame.ID(), l.frame.URL(), l.selector, opts,
)

if err := l.fill("", opts); err != nil {
return fmt.Errorf("clearing %q: %w", l.selector, err)
}

return nil
}

// Click on an element using locator's selector with strict mode on.
func (l *Locator) Click(opts goja.Value) error {
l.log.Debugf("Locator:Click", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)
Expand Down

0 comments on commit 27371aa

Please sign in to comment.