samedi 18 novembre 2017

Dynamically select element based on function parameter

I am creating an Automation Testing framework, and I came up with this function:

    public void DoClick(string selectType, string selector)
    {
        switch (selectType)
        {
            case "ClassName":
                driver.FindElement(By.ClassName(selector)).Click();
                break;
            case "CssSelector":
                driver.FindElement(By.CssSelector(selector)).Click();
                break;
            case "Id":
                driver.FindElement(By.Id(selector)).Click();
                break;
        }
    }

I want to replace the "By..." with something like By[selectType], in order to write a single line of code, instead of the whole switch case. How can I achieve that?

Aucun commentaire:

Enregistrer un commentaire