How to dynamically retrieve the content text of a HTML tag and its child tags?

I would like to know how to dynamically retrieve the content text of a HTML tag and its child tags?

Here is my HTML code, for example:

<p><code>C:<select>
        <option value="test1">test1</option>
        <option value="test2">test2</option>
    </select>test3<select>
        <option value="test4">test4</option>
        <option value="test5">test5</option>
    </select>test6<select>
        <option value="test7">test7</option>
        <option value="test8">test8</option>
        <option value="test9">test9</option>
    </select>test10.txt</code></p>

I would like to create a button after this code, and when it is clicked, I would like to write the content directly within the console.

For example:

C:test2test3test4test6test8test10.txt

or

C:test1test3test5test6test9test10.txt

It might be possible that another paragraph of code only contains 1 or 2 <select> tags. So, I don’t want a code that only works for 3 <select> tags, like in the previous example.

Thank you very much in advance