Girish
Girish

Reputation: 157

how to deal with Line Break <br/> when working with xpath

I am trying to find xpath for the links(Anchor tags <a>) from below HTML code.

Note: I don't want to use absolute xpath, so I am using xpath's contains() function

<div class="productList">
   <table class="product-listing-table">
     <thead>
        <tr>
           <th class="product-desc">
              <a class="pt_sort">Product & Description</a>
           </th>
            <th>
               <a class="pc_sort">
                 Product
                 <br/>
                 Category
               </a>
            </th>
       </tr>
    </thead>
  </table>
</div>

Below xpath gives me 'Product & Description', But in similar way if I am trying to find the next product with text as 'Product Category', it gives me error

.//th/a[contains(text(),'Product & Description')]

Above xpath Works

.//th/a[contains(text(),'Product Category')]

This one does not works.

Can somebody help?

Upvotes: 1

Views: 1668

Answers (1)

Santoshsarma
Santoshsarma

Reputation: 5667

Try with below xpath

"//a[contains(text(),'Product') and contains(.,'Category')]"

Here contains(.,'Category') check for the inner text of any child tags of given tag

Upvotes: 2

Related Questions