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

[Question]How to enter text in div tag in playwright test tool? #2297

Closed
maheshpatnam opened this issue May 19, 2020 · 5 comments
Closed

[Question]How to enter text in div tag in playwright test tool? #2297

maheshpatnam opened this issue May 19, 2020 · 5 comments

Comments

@maheshpatnam
Copy link

maheshpatnam commented May 19, 2020

I am getting error( Error: Element is not an , <textarea> or [contenteditable] element.) when i try to enter text in div tag
Here is code.

await page.mainFrame().waitForSelector(sendMesssageBoxSelector);
const sendMessageBox = await page.$(sendMesssageBoxSelector);
await sendMessageBox.click();
await sendMessageBox.fill('hello');
@celeryclub
Copy link
Contributor

Can you provide an example of what your app code looks like using https://codesandbox.io/ or something similar? Otherwise it's impossible to say why this isn't working.

@pavelfeldman
Copy link
Member

page.fill implies that the element you fill is an input, textarea or contentEditable. It needs to receive and process input events in order to be filled. If you'd like to send characters to a non-editable <div>, you can say page.type('hello').

@maheshpatnam
Copy link
Author

Thanks @pavelfeldman @celeryclub It is working when i use page.type('hello').

@kachkaev
Copy link
Contributor

kachkaev commented Dec 6, 2021

If you'd like to send characters to a non-editable <div>, you can say page.type('hello').

Hmm this does not seem to work in Playwright 1.17. The signature of page.type(selector, text) requires at least two arguments. I have used page.type('body', 'hello') and it seems to work, but I’m not sure if this is the 100% right way.

@colemars
Copy link

colemars commented Dec 9, 2021

I would think to use page.keyboard.type('Hello') now.
https://playwright.dev/docs/api/class-keyboard#keyboard-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants