Rayrun
โ† Back to Discord Forum

Simulate Paste?

kentcdodds
kentcdodds

I want to simulate pasting into a text field. What's the best way to do that?

This thread is trying to answer question "What's the best way to simulate pasting into a text field?"

12 replies

platform language, code for what you've tried?

also, the answer to this might depend on what you're trying to do/test and how the fields you're interacting with behave.

Without more concrete context, I'd say start by copying the contents that you want to the clipboard, focusing on the field that you want and issue CTRL+V or the equivalent of the OS you're on, then validate the content on the field.

Similar to what is described here: https://github.com/microsoft/playwright/issues/8114#issue-964733495

kentcdodds
kentcdodds

I guess I assumed there'd be a helper for pasting. Users can paste in a number of ways (right click, shortcut, password app). I want to just emit a paste event and make sure that works.

There is nothing "native" in Playwright ie locator.paste(buffer,contentType), so we have to do this in user/browser land and dispatch a paste event in a page.evaluate(...) ๐Ÿคท

Oh @mookiept cool idea ๐Ÿ˜

Happy to see I brought another approach to the mix rather than reheat something already discussed ๐Ÿ˜…

tphillips8117

Would I be correct in assuming that browser access to the clipboard is risky from a security point of view?

Security would be a stretch, but Privacy, yes! The clipboard is normally behind user permissions, because it is usually a global API and can give access to things copied from external apps or other pages.

Any updates

tphillips8117

@kentcdodds in testing pasting, is that actually testing the browser itself rather than the website? Unless the web page specifically intercepts paste events, there should be no need to test pasting (test your web page, not the browser ๐Ÿ™‚ )

@tphillips8117: > Unless the web page specifically intercepts paste events This is what I was trying to test, yes.

Unless the web page specifically intercepts paste events This is what I was trying to test, yes.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].