如何获得元素位置 - Imacros

时间:2017-03-15 15:57:43

标签: javascript html imacros

我有3种不同类型的HTML元素(重复的,动态的值,我可以计算数字)第一类型元素具有相同的属性(类),但文本不同(我可以在文本中获取元素) ),其他2个具有相同的属性(我可以跨位置获取此元素),所以我想点击第一类元素的位置上的其他2种类型,为此我想知道第一个类型元素位置(什么我发现整个文本)根据第一类元素位置(作为所有),我必须做什么来获得我找到的重复元素的位置?!

编辑:

示例:

<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>

1 个答案:

答案 0 :(得分: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>

我通过&#34;解决了它的功能&#34; ,但用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)
}
}
相关问题