playwrightplaywright-dotnet

How do you get the HTML tag of the control in Playwright?


How do I get the HTML tag of a Locator?

With the following HTML element:

<textarea id="AnySpecialInstructions" name="AnySpecialInstructions" class="form-control"></textarea>

If I get it by the locator of

var locator = Page.Locator("id=AnySpecialInstructions");

How would would you get the HTML tag of textarea?


Solution

  • Assuming you want to get textarea into your variable locator, you can do this:

    var locator = await page.EvaluateAsync<string>("document.querySelector('#AnySpecialInstructions').tagName")