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
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
4 Answers
Reset to default 4You 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');
For new ers to this, later versions of Playwright support the API used by OP. See: https://playwright.dev/docs/api/class-elementhandle#elementhandlegetattributename
This worked for me:
const attr = await page.$eval('.your-locator-class', el => el.src)
You can easily solved it using playwright native getter - .getAttribute('someAttribute');
For example you can write something like that:
const locator = await page.locator('[name="SomeLocator"]').getAttribute('content');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744173388a4561643.html
评论列表(0条)