2017-03-15 87 views
-1

我有3种不同类型的HTML元素(重复的动态值,我无法计算数字)第一个类型元素具有相同的属性(类),但不同的文本(我可以得到横跨文本的元素),其他2具有相同的属性(我可以通过位置获取该元素),所以我想单击第一类元素的位置上的其他两种类型,为此我想先知道类型元素的位置(我发现整个文本)根据第一类型元素位置(所有),我必须做什么才能获得重复元素的位置,我已经找到了?!如何获取元素位置 - Imacros

编辑:

例子:

<div class="class1">Text1</div> //i want it (the pos here is 1 , for both all elements and imacros) 
<div class="class2"></div> //i want to click on it 
<div class="class1">Text2</div> 
<div class="class1">Text1</div> //And it (the pos here is 3 to all elements , but 2 in imacros) 
<div class="class2"></div> //i want to click on it too 
<div class="class1">Text3</div> 
<div class="class1">Text4</div> 
+0

如果您有动态值,请尝试使用iMacros [IMAGESEARCH](http://wiki.imacros.net/IMAGESEARCH)命令或[Kantu web automation](https://kantu.io)工具。 – Tienkamp

+0

@Tienkamp感谢您的帮助,我解决了它,我把答案,[这里](http://stackoverflow.com/a/42877577/7716032),再次感谢。 – MuslimPerson

回答

0

例2:

<div class="class1">Text1</div> 
<div class="class1">Text2</div> 
<div class="class1">Text3</div> 
<div class="class1">Text4</div> 
<div class="class1">Text5</div> //i found this element by text , i want to know (Programmatically with imacros) the POSITION of this element (according to same elements (Similar in some attributes (like class in this case))) 
<div class="class1">Text6</div> 
<div class="class1">Text7</div> 
<div class="class1">Text8</div> 
<div class="class1">Text9</div> 
<div class="class1">Text10</div> 

我解决它以 “为功能”,但JavaScript语言帮助..

我的代码:在(.js)文件中。

for (var i=1;i<10;i++) 
{ 
var macro = "CODE: "; 
macro += "SET !ERRORIGNORE YES\n"; 
macro += "SET !EXTRACT NULL\n"; 
macro += "TAG POS={{i}} TYPE=DIV ATTR=class:class1 EXTRACT=TXT\n"; 
iimPlay(macro); 
if(iimGetLastExtract().search("TEXT5")!=-1) 
{ 
alert("element pos is: " + i) 
} 
}