custom attribute, how to get value on client side?

4 posts, 0 answers
  1. ldc0618
    ldc0618 avatar
    8 posts
    Member since:
    Jun 2007

    Posted 28 Apr 2010 Link to this post


    I am setting a custom attribute to a slider:
    rs.Attributes["menuAttributeID"] = menuAttributeID.ToString();

    the html output looks correct:
    <div style="height: 22px; width: 200px;" menuattributeid="251" class="RadSlider RadSlider_Default" id="dnn_ctr456_Admin_rtbMenuAdmin_i6_i0_sldHeight">...

    but how do I get the value of menuattributeid on the client side?

    I've tried several things such as:
    var menuAttributeID = sender.get_menuattributeid;
            alert(menuAttributeID);

    but its not working.

    Thanks!







  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 04 May 2010 Link to this post

    Hello ldc0618,

    In order to get the attribute you should reference the element in which HTML the attribute is rendered and extract it by using the getAttribute method. In this case, this element is the element of the slider which is rendered by the server and which can be referenced by using the get_element method. Please examine the following code snippet I prepared for you:


    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
      
            function GetAttribute()
            {
                var slider = $find("<%=RadSlider1.ClientID %>");
                var attr = slider.get_element().getAttribute("menuattributeid");
                alert("menuattributeid is: " + attr);
            }
          
        </script>
        <telerik:RadSlider ID="RadSlider1" runat="server" menuattributeid="251">
        </telerik:RadSlider>
        <asp:Button ID="btn" runat="server" Text="Get custom attribute" OnClientClick="GetAttribute();return false;" />
        </form>
    </body>
    </html>

    Please, use the above as a start point for your implementation and let me know how it goes.

    All the best,
    Svetlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Austin
    Austin avatar
    17 posts
    Member since:
    Sep 2015

    Posted 20 Sep 2018 Link to this post

    I have located a web element via xpath and save it in variable like 

    Element element_name = //a[@class='k-button k-button-icontext k-primary k-grid-update']

    I want to extract certain attribute value against it likes text() and its id.

    What is the coded step process for it.

    I tried with element_name.getattribute(text) its not working.

     

    Please help me with all sort of these similar commands.

  4. Nikolai
    Admin
    Nikolai avatar
    111 posts

    Posted 21 Sep 2018 Link to this post

    Hi Austin,


    This forum thread is referring Telerik ASP.NET Ajax Slider control but it seems you're trying to do automation tests via Telerik TestStudio or Testing Framework is this correct?
    Assuming you are trying to do test automation the easiest way to get an Element's text is to use the TextContent property, here is a working example against Kendo button control:
    this.ActiveBrowser.NavigateTo("https://demos.telerik.com/kendo-ui/button/index");
    this.ActiveBrowser.WaitUntilReady();
                 
    var element = this.ActiveBrowser.Find.ById("textButton");
    Assert.IsNotNull(element);
                 
    string text = element.TextContent;



    Regards,
    Nikolai
    Progress Telerik 
Back to Top