简体   繁体   English

使用Selenium Java为过滤器窗格“铅笔图标”定位元素时出现问题

[英]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. 问题是所有12个过滤器都具有相同的元素。 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: 您可以使用下面的xpath查找元素并相应地更改索引值:

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 筛选器名称1 ----图标

Filter Name 2 ---- icon 筛选器名称2 ----图标

and so on... 等等...

What you will have to do is first locate "Filter Name 1" element and then locate next icon associated to it. 您需要做的是首先找到“过滤器名称1”元素,然后找到与其关联的下一个图标。

Will be helpful if you could add more details into your post to show the Filter names and their HTML code. 如果您可以在帖子中添加更多详细信息以显示过滤器名称及其HTML代码,将很有帮助。

Basically the HTML above / before 基本上是上面/之前的HTML

<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 : 如果确定具有相同属性的元素:By.xpath(“(// div [@ title ='Edit Filter']))并且不止一个,请通过以下方式收集它们:

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 : 然后使用indexValue获取所需的元素:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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