Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fill functionality for textarea #1238

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

const resultDone = "done"
const resultNeedsInput = "needsinput"

type (
elementHandleActionFunc func(context.Context, *ElementHandle) (any, error)
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/static/locators.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<div id="divHello"><span>hello</span></div>
<div><span>bye</span></div>
<textarea>text area</textarea>
<p id="firstParagraph" contenteditable="true">original text</p>
<p id="secondParagraph">original text</p>
<select id="selectElement"><option value="option text"></option><option value="option text 2"></option></select>
<select></select>
<script>
Expand Down
Loading