# How to get child webelement using parent webelement

**URL:** <https://forum.robotframework.org/t/how-to-get-child-webelement-using-parent-webelement/6427>\
**Category:** SeleniumLibrary\
**Created:** [5 November 2023 12:24 UTC](https://forum.robotframework.org/t/how-to-get-child-webelement-using-parent-webelement/6427 "2023-11-05T12:24:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkautomation](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/rkautomation/32/3102_2.png) [@rkautomation](https://forum.robotframework.org/u/rkautomation)\
**Post date:** [5 November 2023 12:24 UTC](https://forum.robotframework.org/t/how-to-get-child-webelement-using-parent-webelement/6427/1 "2023-11-05T12:24:50Z")

</div>

parent\_elm = driver.find\_element(By.XPATH, “”)  
child\_elm = parent\_elm.find\_element(By., “”)

I want to implement same thing in robot framework. which some how makes some verification and validation makes it easy.  
Please help to get me the best way to implement.  
Thanks!

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [5 November 2023 13:14 UTC](https://forum.robotframework.org/t/how-to-get-child-webelement-using-parent-webelement/6427/2 "2023-11-05T13:14:40Z")

</div>

Hi Rocky,

I guess the most common version of this is when you have form fields with dynamic id’s so I’ll use that as an example how you can do this.

Consider the following example HTML:

```html
<div>
    <label for="f_6389">Username:</label>
    <input id="f_6389" type="text">
</div>

```

Then you could do the following with SeleniumLibrary:

```plaintext
${myuserid}= Set Variable User123
${usernameid}= Get Element Attribute //div/label[text()="Username:"] for
Input Text ${usernameid} ${myuserid}

```

The `Input Text` line takes advantage of the [Default locator strategy](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Locating%20elements) of the field’s ID

But you can also put variable into the other locator strategies like this:

```plaintext
Input Text //input[@id="${usernameid}"] ${myuserid}

```

Hope that helps,

Dave.

---

<div class="post-metadata">

**Author:** ![Jerzy.Glowacki](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@Jerzy.Glowacki](https://forum.robotframework.org/u/Jerzy.Glowacki)\
**Post date:** [6 November 2023 10:12 UTC](https://forum.robotframework.org/t/how-to-get-child-webelement-using-parent-webelement/6427/3 "2023-11-06T10:12:42Z")

</div>

I think You are looking for chaining locators (search “Chaining locators” in [https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html)). This does pretty much what You’re looking for, i.e. locates the parent element and then searching within that element.
