Finding a text node #text in Selenium Python

  html, python, selenium

I have the following HTML

<div class="detailSection">
            <span>Authorized Person(s) Detail</span>
            <span>
                     <b>Name &amp; Address</b>
            </span>
            <br>
            <br>
            <span>Title&nbsp;MGR</span>
            <br>
            <br>
            "
            EYN, KHASHY    "   
            <span>

               <div>
               100 Wall Street<br>
               NEW YORK, NY 10005<br>
               </div>
    
            </span>
            <br>
            </div>

I would like to extract the EYN, KHASHY portion of the HTML. My Chrome developer tools tells me this is a #text node(?) and I think that is why it is not working with my current code. Although I am not familiar with #text nodes at all but it seems distinct from the HTML.

Currently my code selects all children elements of the <div> which is parent to the #text. As follows:

 persons = driver.find_element_by_xpath('//*[@id="maincontent"]/div[2]/div[6]')
        all_children = persons.find_elements_by_xpath(".//*")
        for child in all_children:
            li_person.append(child.text)
            print(child.text)

This gives me all the text except the EYN, KHASHY. Probably because all other text is part of a certain element as Chrome dev tools tell me when I hover over. The #text "EYN, KHASHY" returns as blank.

How can I select this node and extract this information?

Source: Python Questions

LEAVE A COMMENT