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

Find Element from another Element

1 Answer 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mykola
Top achievements
Rank 1
Mykola asked on 15 Jan 2012, 11:40 AM
Hi,
I am trying to figure out how I can obtain element from another element.
Let's say I already found some element, e.g. <div> container, like this:
Element divPanel = ActiveBrowser.Find.ById("div1");
Now, I need search another element, .e.g. <a> which is inside this <div> container. Moreover this <a> element can not be direct child of <div> element, and can be located more deeper.
So, when I try such code to find this <a> over Xpath expression:
Element anchor = divPanel.Find.ByXPath("//a");
But, in such case I receive first anchor on the page instead of first anchor inside divPanel element.
As I understand all Find.ByXXX methods perform search starting from root page object.
So my question is - how can I use Find.ByXXX methods to start search from specified Dom node ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Anthony
Telerik team
answered on 16 Jan 2012, 05:03 PM
Hello Mykola,

You'll need to access the elements via the HTML Control Suite to achieve this. Try this code:

HtmlDiv divPanel = Find.ById<HtmlDiv>("div1");
HtmlAnchor anchor = divPanel.Find.ByXPath<HtmlAnchor>("//a");
anchor.Click();

Regards,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Mykola
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Share this question
or