Description
openedon Jul 18, 2024
🚀 Feature Request
it would be useful to be able to work out what 'class' an object is programmatically given the ILocator. Similar to the 'tag' functionality in selenium. By 'class' I mean button, text box, link etc.
Example
It would allow you to loop around a list of ILocators from your page object model and then datadrive it from a table. having got the ILocator you would then use a new method to get the object class and perform an action based on that similar to the code block below but not using javascript.
public async Task GetObjTypeAsync(ILocator locator)
{
if (await locator.IsVisibleAsync())
{
string tagName = await locator.EvaluateAsync<string>("element => element.tagName");
string typeName = await locator.EvaluateAsync<string>("element => element.getAttribute('type')");
switch (typeName)
{
case "text":
case "password":
return "text";
case "checkbox":
return "checkbox";
case "submit":
return "button";
default:
if (tagName == "SELECT")
return "dropDown";
else if (tagName == "BODY")
return "text";
else if (tagName == "A")
return "link";
else
return "";
}
}
return "";
}
Motivation
this would support the use of frameworks and datadriving. This is helpful in a scenario where you are filling in a form from a datatable and only have the ILocator and the value. There doesn't appear to be a way to do this unless you rely on javascript (eg await locator.EvaluateAsync("element => element.getAttribute('type')");) which isn't enabled in some of our tests.