Skip to content
Advertisement

getAttribute is not available on the ElementHandle

I’m using playwright version 0.13.0,

I have an instance of ElementHandle, but the getAttribute function is not available, calling it throws an error saying getAttribute is not a function:

await myElem.getAttribute('src')

I double-checked with the debugger, the function is not on the instance.

Also, there’s no equivalent of page.evaluate function for ElementHandle

Advertisement

Answer

You can pass it as an argument to the page.evaluate function:

await page.evaluate(el => el.getAttribute('src'), myElem);

or

await myElem.evaluate(node => node.getAttribute('src');
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement