This is a migrated thread and some comments may be shown as answers.

HTML Custom Control

3 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 16 Jul 2015, 10:24 PM

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

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 21 Jul 2015, 07:53 PM
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
 
0
Nick
Top achievements
Rank 1
answered on 21 Jul 2015, 08:15 PM

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.

 

 

0
Boyan Boev
Telerik team
answered on 24 Jul 2015, 01:18 PM
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
 
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Nick
Top achievements
Rank 1
Share this question
or