From a2b836ad8a8a62b745932cb115b2918636296f1d Mon Sep 17 00:00:00 2001 From: ankur22 Date: Wed, 22 Nov 2023 16:17:31 +0000 Subject: [PATCH] Refactor isHidden to return an error This is for frame, elementHandle and page. --- common/frame.go | 8 ++++---- common/page.go | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/frame.go b/common/frame.go index 762d2e307..425c199e6 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1242,19 +1242,19 @@ func (f *Frame) isDisabled(selector string, opts *FrameIsDisabledOptions) (bool, // IsHidden returns true if the first element that matches the selector // is hidden. Otherwise, returns false. -func (f *Frame) IsHidden(selector string, opts goja.Value) bool { +func (f *Frame) IsHidden(selector string, opts goja.Value) (bool, error) { f.log.Debugf("Frame:IsHidden", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsHiddenOptions(f.defaultTimeout()) if err := popts.Parse(f.ctx, opts); err != nil { - k6ext.Panic(f.ctx, "parsing is hidden options: %w", err) + return false, fmt.Errorf("parsing is hidden options: %w", err) } hidden, err := f.isHidden(selector, popts) if err != nil { - k6ext.Panic(f.ctx, "checking is %q hidden: %w", selector, err) + return false, fmt.Errorf("checking is %q hidden: %w", selector, err) } - return hidden + return hidden, nil } func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, error) { diff --git a/common/page.go b/common/page.go index ca99153c1..f39d472ac 100644 --- a/common/page.go +++ b/common/page.go @@ -909,7 +909,10 @@ func (p *Page) IsEnabled(selector string, opts goja.Value) bool { return p.MainFrame().IsEnabled(selector, opts) } -func (p *Page) IsHidden(selector string, opts goja.Value) bool { +// IsHidden will look for an element in the dom with given selector and see if +// the element is hidden. It will not wait for a match to occur. If no elements +// match `false` will be returned. +func (p *Page) IsHidden(selector string, opts goja.Value) (bool, error) { p.logger.Debugf("Page:IsHidden", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsHidden(selector, opts)