Easiest way to get child elements?

6,170 views
Skip to first unread message

Rick DeNatale

unread,
Mar 17, 2010, 10:55:43 AM3/17/10
to webd...@googlegroups.com
I'm using the selenium-webdriver ruby gem.

I've been looking for a way to find particular child elements once
I've found a particular element. Lets say I've got

...
<tr>
...
<td class="a">...</td>
<td class="b">...</td>
...
</tr>

Assuming that I've retrieved the tr element, I'd like to get the
individual td children by class. I couldn't find an obvious way to do
this. Is there one?

Alternatively is it possible to retrieve the innerHTML of an element?
--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Danny Guerrier

unread,
Mar 17, 2010, 11:03:34 AM3/17/10
to webd...@googlegroups.com
assuming you have the tr element then you can do

List<WebElement> elements = element.findElements(By.tagName("td"));

That'll should give a list of td elements.  I haven't tried it so give it try and see what happens.


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Daniel Wagner-Hall

unread,
Mar 17, 2010, 11:03:58 AM3/17/10
to webd...@googlegroups.com
element = driver.find_element(:tag_name, "tr")
child = element.find_element(:class, "a")

Reply all
Reply to author
Forward
0 new messages