diff --git a/common/locator.go b/common/locator.go index 79ad3199c..b9b22beb2 100644 --- a/common/locator.go +++ b/common/locator.go @@ -257,19 +257,19 @@ func (l *Locator) isVisible(opts *FrameIsVisibleOptions) (bool, error) { // IsHidden returns true if the element matches the locator's // selector and is hidden. Otherwise, returns false. -func (l *Locator) IsHidden(opts goja.Value) bool { +func (l *Locator) IsHidden(opts goja.Value) (bool, error) { l.log.Debugf("Locator:IsHidden", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameIsHiddenOptions(l.frame.defaultTimeout()) if err := copts.Parse(l.ctx, opts); err != nil { - k6ext.Panic(l.ctx, "parsing is hidden options: %w", err) + return false, fmt.Errorf("parsing is hidden options: %w", err) } hidden, err := l.isHidden(copts) if err != nil { - k6ext.Panic(l.ctx, "checking is %q hidden: %w", l.selector, err) + return false, fmt.Errorf("checking is %q hidden: %w", l.selector, err) } - return hidden + return hidden, nil } // isHidden is like IsHidden but takes parsed options and does not diff --git a/tests/locator_test.go b/tests/locator_test.go index daa378b47..a958e0f92 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -344,7 +344,7 @@ func TestLocatorElementState(t *testing.T) { { "hidden", `() => document.getElementById('inputText').style.visibility = 'hidden'`, - func(l *common.Locator) bool { return !l.IsHidden(nil) }, + func(l *common.Locator) bool { resp, _ := l.IsHidden(nil); return !resp }, }, { "readOnly", @@ -398,7 +398,11 @@ func TestLocatorElementState(t *testing.T) { "IsDisabled", func(l *common.Locator, tb *testBrowser) { l.IsDisabled(timeout(tb)) }, }, { - "IsHidden", func(l *common.Locator, tb *testBrowser) { l.IsHidden(timeout(tb)) }, + "IsHidden", func(l *common.Locator, tb *testBrowser) { + if _, err := l.IsHidden(timeout(tb)); err != nil { + panic(err) + } + }, }, } for _, tt := range sanityTests {