'find out all child elements xpath from parent xpath using selenium webdriver in python

I can find the element by xpath of driver.find_element_by_xpath('//*[@id="app"]/table/tbody/tr[1]/td[1]'). but any way i can return all children elements like tag and tag xpath?

<tr>
    <td class="">
        <div>
            <a href="/user/1">
                <!-- react-text: 6011 -->user first name |
                <!-- /react-text -->
                <!-- react-text: 6012 -->
                <!-- /react-text -->
                <!-- react-text: 6013 -->user last name
                <!-- /react-text -->
            </a>
            <div>
                <span>
            <!-- react-text: 6014 -->town<!-- /react-text -->
            <!-- react-text: 6015 -->  | <!-- /react-text -->
            <!-- react-text: 6015 -->month<!-- /react-text -->
            <!-- react-text: 6081 --> | date<!-- /react-text -->
            <!-- react-text: 6082 -->year<!-- /react-text -->
            </span>
            </div>
        </div>
    </td>
    <td class=""><a href="/address/1">1</a>
        <div class="">city</div>
    </td>
</tr>


Solution 1:[1]

The key is to use the xpath .//* to get all the children for current node. The . picks the current element & //* selects all the elements, which makes the whole xpath to select all child elements of current element. Your code will look like this:

parent_elem = driver.find_element_by_xpath('//*[@id="app"]/table/tbody/tr[1]/td[1]')
child_elements = parent_elem.find_elements_by_xpath('.//*')

Solution 2:[2]

if you need to find immediate children, use

child_elements = parent_elem.find_elements_by_xpath('./*')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jayesh Doolani
Solution 2 Andrey S