ExecuteAutomation

Custom methods for control in Selenium C# (Part 2)

In the last post of this series we discussed how to write custom methods for control which perform Set operations in UI controls, in this post we will write code which perform Get operations out from a control like getting text value from UI controls. We will write code to Get values out from controls like Here is the video of the above discussion Here is the complete code from above video Getting value from Textbox
//Getting value out from Textbox
public static string GetText(IWebDriver driver, string element, PropertyType elementtype)
{
    if (elementtype =="Id")
        return driver.FindElement(By.Id(element)).GetAttribute("value");
    if (elementtype == "Name")
        return driver.FindElement(By.Name(element)).GetAttribute("value");
    else return String.Empty;

}
Getting Value from DropDownList box
//Getting value from Dropdownlist
public static string GetTextFromDDL(IWebDriver driver, string element, PropertyType elementtype)
{
    if (elementtype == "Id")
        return new SelectElement(driver.FindElement(By.Id(element))).AllSelectedOptions.SingleOrDefault().Text;
    if (elementtype == "Name")
        return new SelectElement(driver.FindElement(By.Name(element))).AllSelectedOptions.SingleOrDefault().Text;
    else return String.Empty;
}
Thanks for watching the video and reading the post!! Please leave your comments and let me know if there is anything need to be improved in the post!!! Thanks, Karthik KK