简体   繁体   中英

Problem locating the element for a filter pane 'pencil Icon' using Selenium Java

I am working on a business intelligence dashboard. On the filter pane, they all have a pencil icon that you can click to edit that specific filter. The issue is that all 12 filters have the same element. How do I select the individual filter pencil? <div class="ew-i-fx ew-i-act f-act" data-ng-click="levelMainAction($event, level, $index)" data-ng-show="!item.disabled &amp;&amp; !item.locked" data-ng-class="{running: opened.edit == 'l'+$index}" data-translate="" data-translate-attr-title="we.actions.editfilter" title="Edit Filter"></div>

在此处输入图片说明

If all the attributes of all the filters are same and if the position of the filters are not changing, then you can use index to identity the filter.
You can use the below xpath to find the element and change the index value accordingly:

WebElement element = driver.findElement(By.xpath("(//div[@title='Edit Filter'])[1]"));

For each of these icon I am sure there must be a text or label or title associated to it on the left.

For example -

Filter Name 1 ---- icon

Filter Name 2 ---- icon

and so on...

What you will have to do is first locate "Filter Name 1" element and then locate next icon associated to it.

Will be helpful if you could add more details into your post to show the Filter names and their HTML code.

Basically the HTML above / before

<div class="ew-i-fx ew-i-act f-act" data-ng-click="levelMainAction($event, level, $index)" data-ng-show="!item.disabled &amp;&amp; !item.locked" data-ng-class="{running: opened.edit == 'l'+$index}" data-translate="" data-translate-attr-title="we.actions.editfilter" title="Edit Filter"></div>

If you sure with the elements having same properties : By.xpath("(//div[@title='Edit Filter']) and it more than one, then collect them by :

import java.util.List;
import org.openqa.selenium.WebElement;

List<WebElement> elements = driver.findElements(By.xpath("(//div[@title='Edit Filter']));

And the use indexValue to get the element you want :

int indexValue = 1;
elements.get(indexValue).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM