Equivalent of by.name selector in playwright

Viewed 3319

I have been trying to learn playwright and during the course of implementation I am trying to write a test case which find an input element by Name and fills it with some values

Unfortunately, the element has only class and name attributes. I have been trying to find a way to read it but did not found anything on the docs or I might have missed

Kindly help

1 Answers

Not direct answer, but a work around. You can specify your css selector to search for the name attribute:

Structure is:

<tag>[attribute='value']

For example: This html (which is on this page if you view the dom):

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">

Is identified with this css:

meta[name='viewport']

It is also possible without a tag and only by the name, see the following example:

await page.click(`[name='my-value']`);

screenshot of devtools with identifier

Related