How to find Nested elements within ObjectModel Element

4 posts, 0 answers
  1. Govind
    Govind avatar
    13 posts
    Member since:
    Aug 2014

    Posted 23 May Link to this post

    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

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 26 May Link to this post

    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!
  3. Govind
    Govind avatar
    13 posts
    Member since:
    Aug 2014

    Posted 26 May in reply to Boyan Boev Link to this post

    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

     

  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 30 May Link to this post

    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!
Back to Top