Rayrun
← Back to Discord Forum

Playwright_TypeScript: Pass HTMLElement as a function parameter, achieve using document.

megha.krishnanposted in #help-playwright
Open in Discord
megha.krishnan

How can I pass a HTMLElement found using the below code into a function?

const elementHandle = await page.evaluate(() => { const element = document.getElementById('FILTER_BOX') as HTMLInputElement; return element; ----- expecting to returns the HTMLElement. })

const action = new className(elementHandle); --elementHandle is passed as a parameter during an object creation (action). await action.applyFilter("FILTERBOX_VALUE");

But gets an error saying the passed is not a HTMLElement.

How can we resolve this in typescript.

This thread is trying to answer question "How can I pass a HTMLElement as a function parameter in TypeScript using Playwright?"

1 reply

You cannot pass complex objects between the browser and Node.js see here: https://playwright.dev/docs/evaluating So you most likely want to stay inside evaluate for your action class or use Locators instead in the Node.js world.

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 luc@ray.run.