Skip to content

[Feature]: Provide functionality to work out an objects class #31759

Closed

Description

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions