<div class=”ag-cell-label-container ag-header-cell-sorted-none” role=”presentation”
<span ref=”eMENU” class=”ag-header-icon ag-header-cell-menu-button” aria-hidden=”true” style=”transition:opacity 0.2s;>
<span class=”ag-icon ag-icon-menu”></span>
</span>
<div ref=”eLabel” class=”ag-header-cell-label” role=”presentation”>
<span ref=”eText” class=”ag-header-cell-text role=”columnheader”> Product</span>
Мне нужно нажать на ag-icon ag-icon menu
в моем приложении для столбца Продукт.
Я написал ниже xpath, чтобы сделать то же самое. Но существует более 1 элемента, соответствующего xpath, указанному в одноуровневом элементе, и поэтому я жестко закодировал вхождение как [1]. Есть ли способ получить клик по ag-icon ag-icon menu
без использования ссылки?
WebElement pipeline = driver.findElement(By.xpath("//span[text()='Product']"));
WebElement parent = pipeline.findElement(By.xpath(".."));
WebElement sibling = parent.findElement(By.xpath("(//preceding-sibling::span[@class='g-header-icon ag-header-cell-menu-button']/span)[1]"));
sibling.click();