ratsstack
ratsstack

Reputation: 1021

How do I get a value from HTML with multiple classes with same name?

ow do I get the value of "Feb 2015" from HTML below? The problem I'm facing is there can be multiple "col-lg-4 col-md-6" classes or just a single one, depending on how much information a user provides about themselves:

<div class="row">

            <div class="col-lg-4 col-md-6">
                <dl>
                    <dt>Resident Since</dt>
                    <dd>Mar 2013</dd>
                </dl>
            </div>

                                <div class="col-lg-4 col-md-6">
                    <dl>
                        <dt>Hometown</dt>
                        <dd>New York</dd>
                    </dl>
                </div>

                                <div class="col-lg-4 col-md-6">
                    <dl>
                        <dt>Occupation</dt>
                        <dd>Builder</dd>
                    </dl>
                </div>

            <div class="col-lg-4 col-md-6">
                <dl>
                    <dt>Joined</dt>
                    <dd>Feb 2015</dd>
                </dl>
            </div>

        </div>

Upvotes: 1

Views: 91

Answers (1)

Saifur
Saifur

Reputation: 16201

Multiple ways to do this. If you want to find the xpath based on the what you have in dt, since that makes sure that a joined date then do the following xpath

//div[@class='col-lg-4 col-md-6']//dt[.='Joined']/../dd

Or, if it is always the last child you can use the following css

.col-lg-4.col-md-6:last-child dd

Upvotes: 2

Related Questions