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

How to perform actions on an element by finding its parent element

1 Answer 136 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sudarshan
Top achievements
Rank 2
Sudarshan asked on 27 Apr 2013, 11:02 AM
<div class="jsdomenuitem"................................ //parent
   Text - Aggregations
   <div class = "jsdomenuarrow" id = "menuitem209arrow"  //child

Hi,

I'm able to find the parent using Innertext property, by getting this i want to click the child. Child doesnt contain any innertext 
I'm able to find the child by using id=menuitem209arrow but there are many cases like this, so instead of finding the child directly, i want to find Parent  and they perform actions on child.

How to get the child by finding the parent?

Thanks
Sudarshan

1 Answer, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 29 Apr 2013, 09:39 AM
Hi Sudarshan,

You can use the ChildNodes collection which contains all children of a parent element.

I created a simple application to demonstrate it:

HTML:

<!DOCTYPE html>
<html>
<head>
<title>Div</title>
</head>
<body>
<div class="jsdomenuitem">
Aggregations
    <div id="menuitem209arrow">
    Child
    </div>
</div>
</body>
</html>

C#:

HtmlDiv parrent = ActiveBrowser.Find.ByContent<HtmlDiv>("Aggregations");
Element child = parrent.ChildNodes[1];
HtmlDiv ch = child.As<HtmlDiv>();
ch.Click();

I recorded a short video as a demonstration.

Hope this helps.

Kind regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Sudarshan
Top achievements
Rank 2
Answers by
Boyan Boev
Telerik team
Share this question
or