Caelaran
Caelaran

Reputation: 45

Xpath keeps selecting all objects of the given class instead of the first

This one has me stumped., I'm trying to select the first class = csb-quantity-listbox object of the below using the XPATH //select[@class='csb-quantity-listbox'][1], but instead of selecting the first quantity listbox it's selecting ALL the listboxes on the page with that class (see image below).

What am I doing wrong?

<div class="gwt-product-detail-products-container">
   <div class="gwt-product-detail-products-header-column">
   </div>
   <div id="gwt-product-detail-widget-id-12766" class="gwt-product-detail-widget">
    <div class="gwt-product-detail-widget-image-column ui-draggable" title="12766">
        <div class="gwt-product-detail-widget-options-column">
        </div>
        <div class="gwt-product-detail-widget-price-column">
        </div>
        <div class="gwt-product-detail-widget-quantity-panel">
                <select class="csb-quantity-listbox" name="quantity_12766"></select>
            </div>
            <div class="gwt-bundle-add-to-cart-btn">
            </div>
        </div>
    </div>
    <div id="gwt-product-detail-widget-id-10617" class="gwt-product-detail-widget">
        <div class="gwt-product-detail-widget-image-column ui-draggable" title="10617">
            <div class="gwt-product-detail-widget-options-column">
            </div>
            <div class="gwt-product-detail-widget-price-column">
            </div>
            <div class="gwt-product-detail-widget-quantity-panel">
                <select class="csb-quantity-listbox" name="quantity_10617"></select>
            </div>
            <div class="gwt-bundle-add-to-cart-btn">
            </div>
        </div>
    </div>
</div>

Image:

enter image description here

Upvotes: 1

Views: 40

Answers (1)

Bensonius
Bensonius

Reputation: 1541

You just need to put brackets around the statement before the [1]

Like so:

(//select[@class='csb-quantity-listbox'])[1]

Upvotes: 1

Related Questions