Site Loader
Auckland, New Zealand
In last post of Refactoring custom methods of control libraries, we discussed how to
  • Reduced number of parameters
  • Strongly-typed parameters
  • More reusable
In this post, we will discuss reducing the number of parameters even further to more granular level after the introduction of Page Object Model in our code, please read my previous post for more details on POM Here is the complete video for the above discussion Here is the complete code Set Methods for controls like Textbox, Button, DropDownList box.
    //Enter text in the Textbox
    public static void EnterText(IWebElement element,string value)
    {
            PropertiesCollection.driver.FindElement(By.Id(element)).SendKeys(value);

    }

    //Click into a button, Checkbox, option etc
    public static void Click(IWebElement element)
    {
            PropertiesCollection.driver.FindElement(By.Name(element)).Click();
    }

    //Selecting a drop down control
    public static void SelectDropDown(IWebElement element, string value)
    {
            new SelectElement(PropertiesCollection.driver.FindElement(By.Name(element))).SelectByText(value);
    }
Get Methods for controls like Textbox and DropDownList box
    public static string GetText(IWebElement element)
    {
            return PropertiesCollection.driver.FindElement(By.Name(element)).GetAttribute("value");
    }

    public static string GetTextFromDDL(IWebElement element)
    {
            return new SelectElement(PropertiesCollection.driver.FindElement(By.Name(element))).AllSelectedOptions.SingleOrDefault().Text;
    }
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

Post Author: Karthik kk

6 Replies to “Customizing Custom library methods”

  1. Hi,

    I tried your POM example code to select dropdown list using telerik RadComboBox but got
    NoSuchElementException: Cannot find element by: By.Id

    The aspx code for the RadComboBox is below. The selections are dynamically generated from the dropdown when click the arrow to view list.

    Can you please provide a sample code example?

    Select Study / Site

    select

    1. The html code did get posted. Please see below..

      div class=”content-left-box”>
      div class=”content-left-box-text”>
      h3>Select Study / Site
      div>
      ul>
      li>
      div id=”ctl00_ContentPlaceHolderLeft_ArcosLeftColumn_rcbProtocol” class=”RadComboBox RadComboBox_Default” style=”width:160px;”>
      table class=”” style=”border-width: 0px; border-collapse: collapse;” summary=”combobox”>
      tbody>
      tr class=”rcbReadOnly”>
      td class=”rcbInputCell rcbInputCellLeft” style=”width:100%;”>
      input id=”ctl00_ContentPlaceHolderLeft_ArcosLeftColumn_rcbProtocol_Input” class=”rcbInput radPreventDecorate rcbEmptyMessage” type=”text” readonly=”readonly” value=”Select Study / Site” name=”ctl00$ContentPlaceHolderLeft$ArcosLeftColumn$rcbProtocol” autocomplete=”off”>
      /td>
      td class=”rcbArrowCell rcbArrowCellRight”>
      /tr>
      /tbody>
      /table>
      div class=”rcbSlide” style=”z-index: 6000; display: none; width: 310px;”>
      input id=”ctl00_ContentPlaceHolderLeft_ArcosLeftColumn_rcbProtocol_ClientState” type=”hidden” name=”ctl00_ContentPlaceHolderLeft_ArcosLeftColumn_rcbProtocol_ClientState” autocomplete=”off”>
      /div>
      /li>
      /ul>
      /div>
      /div>
      /div>

Leave a Reply

Your email address will not be published. Required fields are marked *