大家好,我有这样的站点布局,我想通过 XPATH 访问带有 @class product-grid 的元素,但同时考虑到如果邻居有 category-grid 类我将无法到达那里的条件换句话说,如果不是类别网格邻居,则转到产品网格
<div class="page-body">
<div class="category-grid"><span>Есть категория</span></div>
<div class="product-selectors"></div>
<div class="product-filters"></div>
<div class="product-grid">
<div>..Не должен найти..</div>
</div>
</div>
//div[1][@class='product-selectors' or contains(@class,'slider-wrapper') or contains(@class,'category-description')]/parent::div/div[contains( @class,'product-grid')]
我使用了这个设计并且它有效,但是,这些元素并不总是放在首位
<div class="page-body">
<div class="slider-wrapper"><span></span></div>
<div class="product-selectors"></div>
<div class="product-filters"></div>
<div class="product-grid">
<div>..Должен найти..</div>
</div>
</div>
<div class="page-body">
<div class="slider-wrapper"><span></span></div>
<div class="category-grid"><span>Есть категория</span></div>
<div class="product-filters"></div>
<div class="product-grid">
<div>..Не Должен найти..</div>
</div>
</div>
我们正在寻找
div[contains(@class,'product-grid')
并检查没有邻居div[@class='category-grid']