How to get child webelement using parent webelement

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.

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:

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

Then you could do the following with SeleniumLibrary:

${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 of the field’s ID

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

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

Hope that helps,


I think You are looking for chaining locators (search “Chaining locators” in This does pretty much what You’re looking for, i.e. locates the parent element and then searching within that element.

1 Like