简体   繁体   中英

select text of element using xpath with selenium

I have a structure like this :

<div class="content">
    <h3 class="faq">Joocey</h3>
        Locked Bag 4005
        <br> 
        6/78 William Street
        <br>
        Sydney NSW 2000
        <br> Customer Care: <a href="tel:1300886534">1300886534</a><br>
        or<br> help@joocey.com.au<br> <br>
        <div class="greenbar">
            <a href="/Stores">See All Stores <i class="icon-chevron-right icon-white pull-right">    </i</a>
        </div>
                    <!--greenbar-->

                    <!--main_footer-->
</div>

How to select each text line in div[@class="content"] ?

For example, I want to select : "Joocey", "Locked Bag 4005", "6/78 William Street", "SydneyNSW 2000", "Customer Care:", "1300886534".

I have tried "//div[@class='content'][text()[2]]" to select "Locked Bag 4005" but it always select all text. Any help would be great.

When you are selecting text by one of the DOM selectors, there is no concept of "line".

You are going to have to grab all of the text in div[@class="content"] , and then manipulate that as a string. Break it up on the new-line characters, and then access the resulting array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM