OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

In Playwright, is there - knowing its id - a way to identify the type of an element?

  • Thread starter Thread starter Clarius
  • Start date Start date
C

Clarius

Guest
In Playwright, is there - knowing its id - a way to identify the HTML tag type of an element? Consider this. I know the id but want to identity its HTML tag type i.e. select or input. Can I do something like...

Code:
let typeOfTag = page.locator(`#${id}`).type();
switch (typeOfTag){
  case "input":
    page.locator(`#${id}`).fill(data[id]);
    break;
  case "select":
    page.locator(`#${id}`).selectOption(data[id]);
    break;
  default:
    // none
}

<p>In Playwright, is there - knowing its id - a way to identify the HTML tag type of an element? Consider this. I know the id but want to identity its HTML tag type i.e. select or input. Can I do something like...</p>
<pre><code>let typeOfTag = page.locator(`#${id}`).type();
switch (typeOfTag){
case "input":
page.locator(`#${id}`).fill(data[id]);
break;
case "select":
page.locator(`#${id}`).selectOption(data[id]);
break;
default:
// none
}
</code></pre>
 
Top