HTML Custom Control

4 posts, 0 answers
  1. Nick
    Nick avatar
    2 posts
    Member since:
    Jun 2015

    Posted 16 Jul 2015 Link to this post

    I am trying to create a custom HTML control for the h3 tag and am having trouble.  I'm using the thread http://www.telerik.com/forums/custom-web-controls for a reference but am unable to get it to work.  I'm using the Find.ByAttributes<HtmlH3>("class=~someclass") but am not receiving only h3 elements.  Here is my code:

        public class HtmlH3 : HtmlControl
        {
            ArtOfTest.Common.IFindExpression _locatorExpression;

            public HtmlH3(Element element) : base(element)
            {
                _locatorExpression = new HtmlFindExpression("tagname=h3");
            }
            
            public HtmlH3() : base()
            {
                _locatorExpression = new HtmlFindExpression("tagname=h3");
            }
                    public override ArtOfTest.Common.IFindExpression LocatorExpression
            {
                get { return _locatorExpression; }
            }
        }

     

    Help would be greatly appreciated.  Thanks

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 21 Jul 2015 Link to this post

    Hi Nick,

    What issue exactly do you experience?

    Please elaborate also a bit more why do you want to implement a custom class.

    You can directly find h3 element by this find expression:

    Element h3 = ActiveBrowser.Find.ByExpression("tagname=h3");

    Looking forward to hearing from you.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Nick
    Nick avatar
    2 posts
    Member since:
    Jun 2015

    Posted 21 Jul 2015 in reply to Boyan Boev Link to this post

    Thank you for your response! 

    What I was trying to do was run a command such as:

    Manager.ActiveBrowser.Find.​ByContent<HtmlH3>("p:Some Content");

    Which would return only h3 elements that matched the content expression.  

    Basically my project that I am working on testing is big and I was trying to avoid having to add the Find.ByExpression("tagname=h3") for every h3 that I needed to retrieve.

     

     

  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 24 Jul 2015 Link to this post

    Hello Nick,

    Manager.ActiveBrowser.Find.​ByContent<HtmlH3>("p:Some Content"); will return only the first element with text "p:Some Content". 

    In order to return a list you should use 

    Manager.ActiveBrowser.Find.AllByContent<HtmlH3>("p:Some Content");

    Let me know if that helps.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top