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

How to find Nested elements within ObjectModel Element

3 Answers 304 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Govind
Top achievements
Rank 1
Govind asked on 24 May 2016, 12:54 AM

how to find nested elements within the ArtOfTest.WebAii.ObjectModel.Element.

I want to a span element within a form. The form has a unique attribute, span element does not have unique attribute. We cannot go by TagIndex, since the content is dynamic.

We would like to use Element objectmodel and not HtmlControl type. The element has the property FindUsedExpression, but there is no option to find the nested element.

sample code:

                Element parent = Manager.ActiveBrowser.Find.ByExpression(parentattribute); // parent
                if (parent != null) {

                    Htmlcontrol control = parent.As<HtmlControl>();
                    HtmlControl child = control.Find.ByExpression<HtmlControl>(childattributes); // child ---- i don't want
                    if (child != null) {
                        child .Focus(); // focus;

                    }

                }

regards

govind

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 26 May 2016, 12:13 PM
Hello Govind,

Please send me a screen shot of the DOM tree with the form and span so I can help you with the code.

Thank you!

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Govind
Top achievements
Rank 1
answered on 27 May 2016, 12:47 AM

Hello Boyan,

The known facts

1) I can cast an ObjectModel Element to HtmlControl -- element.As<HtmlControl>()

2) There is no option to find nested element through Object Model Element

3) There is option to find nested child through HtmlControl

4) Can find an element through by various HtmlFindExpression or FindExpression

5) Not all elements can be parsed as HtmlControl. Element Object Model is very useful for labels, paragraphs, etc.

We want to find a nested <label>,<p>,<h1>, <h2>, <h3>, <i>, etc.. Element Object is very handy.

6) Another feature of Element Object is the ability to detect and verify if we have got hold of the right element through property - element.Content or ParsedElement..... This feature is not available in HtmlControl

My requirement is

a) There are scenarios where you get complex nested structure generated dynamically. Only the Parent has an unique identity..

b) I want to have a generic API where we can use both HtmlControl & Element. This allows us with more flexibility to locate the exact element we are after in verification.

c) Have attached the sample file, along with the html and screen shot.

My expectation:

1) Find nested ObjectModel Element  [ not HtmlControl ]

2) Cast HtmlControl to ObjectModel Element.

Thanks

Govind

 

0
Boyan Boev
Telerik team
answered on 30 May 2016, 02:28 PM
Hi Govind,

Here is simple code which finds first the parent div which contains both the link and the input, hovers over the link and prints the text of the input into the log:

ActiveBrowser.RefreshDomTree();
//Find the parent Div
HtmlDiv parent = ActiveBrowser.Find.ById<HtmlDiv>("paymentDetail");
//Find the link with 1 - Payment Number text
HtmlAnchor link = parent.Find.ByContent<HtmlAnchor>("1 - Payment Number");
//Hover over the link
link.MouseHover();
//Find the text of the Payment Number Input
HtmlInputText text = parent.Find.ByAttributes<HtmlInputText>("name=PaymentNumber");
//Print the its placeholder to the log
Log.WriteLine(text.Placeholder.ToString());


If you want to cast an html control to element you can simply use the BaseElement:

parent.BaseElement

Let me know if that helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Govind
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Govind
Top achievements
Rank 1
Share this question
or