使用 xpath 时如何处理换行符 <br/>

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

我正在尝试从下面的 HTML 代码中找到链接(锚标记 <a>)的 xpath。

注:我不想用绝对的xpath,所以我用的是xpath的contains()函数

<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>

下面的 xpath 给我 'Product & Description',但是如果我试图找到下一个文本为 'Product Category' 的产品,它会给我错误

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

以上 xpath 有效

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

这个不行。

有人可以帮忙吗?

试试下面的 xpath

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

此处 包含(.,'Category') 检查给定标签

的任何子标签的内部文本