diff --git a/common/element_handle.go b/common/element_handle.go index 2f6d44aa7..d206c65c9 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -24,6 +24,7 @@ import ( ) const resultDone = "done" +const resultNeedsInput = "needsinput" type ( elementHandleActionFunc func(context.Context, *ElementHandle) (any, error) @@ -270,7 +271,10 @@ func (h *ElementHandle) fill(_ context.Context, value string) error { if !ok { return fmt.Errorf("unexpected type %T", result) } - if ok && s != resultDone { + + if s == resultNeedsInput { + h.frame.page.Keyboard.InsertText(value) + } else if s != resultDone { // Either we're done or an error happened (returned as "error:..." from JS) return errorFromDOMError(s) } diff --git a/tests/locator_test.go b/tests/locator_test.go index 6e2fc179e..d41ca44a7 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -103,6 +103,22 @@ func TestLocator(t *testing.T) { require.Equal(t, value, p.InputValue("#inputText", nil)) }, }, + { + "FillTextarea", func(tb *testBrowser, p *common.Page) { + const value = "fill me up" + p.Locator("textarea", nil).Fill(value, nil) + require.Equal(t, value, p.InputValue("textarea", nil)) + }, + }, + { + "FillParagraph", func(tb *testBrowser, p *common.Page) { + const value = "fill me up" + p.Locator("#firstParagraph", nil).Fill(value, nil) + require.Equal(t, value, p.TextContent("#firstParagraph", nil)) + l := p.Locator("#secondParagraph", nil) + assert.Panics(t, func() { l.Fill(value, nil) }, "should panic") + }, + }, { "Focus", func(tb *testBrowser, p *common.Page) { focused := func() bool { diff --git a/tests/static/locators.html b/tests/static/locators.html index 13ff8f8fa..394035ea2 100644 --- a/tests/static/locators.html +++ b/tests/static/locators.html @@ -16,6 +16,8 @@
original text
+original text