How to Get element Position ?!

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
MuslimPerson
Posts: 5
Joined: Wed Mar 15, 2017 4:01 pm

How to Get element Position ?!

Post by MuslimPerson » Wed Mar 15, 2017 4:39 pm

I have 3 different types of HTML Elements (repeated , dynamic values, i can't count the numbers) first type elements have same attribute (class) , but different in text (i can get the element across the text) , the other 2 have same attributes (i can get this element across the Position) , so i want to click on the other 2 types across the Position of first type of elements , for this i want to know first type element Position (what i found across the text) according first type elements Positions (as all) , what i have to do to get the Position of repeated element i have found ?! :idea:

Example:

Code: Select all

<div class="class1">Text1</div> //i want it (by text) , the pos here is 1 , for both all elements and imacros
<div class="class2"></div> //i want to click on it (by Position)
<div class="class1">Text2</div>
<div class="class1">Text1</div> //And it (by text) the pos here is 3 to all elements , but 2 in imacros
<div class="class2"></div> //i want to click on it too (by Position)
<div class="class1">Text3</div>
<div class="class1">Text1</div> //And it (by text) the pos here is 5 to all elements , but 3 in imacros
etc....
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to Get element Position ?!

Post by chivracq » Wed Mar 15, 2017 7:20 pm

MuslimPerson wrote:I have 3 different types of HTML Elements (repeated , dynamic values, i can't count the numbers) first type elements have same attribute (class) , but different in text (i can get the element across the text) , the other 2 have same attributes (i can get this element across the Position) , so i want to click on the other 2 types across the Position of first type of elements , for this i want to know first type element Position (what i found across the text) according first type elements Positions (as all) , what i have to do to get the Position of repeated element i have found ?! :idea:

Example:

Code: Select all

<div class="class1">Text1</div> //i want it (by text) , the pos here is 1 , for both all elements and imacros
<div class="class2"></div> //i want to click on it (by Position)
<div class="class1">Text2</div>
<div class="class1">Text1</div> //And it (by text) the pos here is 3 to all elements , but 2 in imacros
<div class="class2"></div> //i want to click on it too (by Position)
<div class="class1">Text3</div>
<div class="class1">Text1</div> //And it (by text) the pos here is 5 to all elements , but 3 in imacros
etc....
Welcome to the Forum and Thanks for answering directly a few Threads but refrain from your religious Comments in each of your Posts as I had to disapproved them all. (I still posted them on your behalf...)

This is a Technical Forum, we don't care (and don't want to care) about your religious, political or sexual Orientation...

>>>

CIM...! :mrgreen: (Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Browsers/Version...)

For your Case, I'm not completely sure I understand your Scenario/Requirements exactly but it looks to me like a typical Case for Relative Positioning... ('POS=1/2/3/etc' on the Anchor and 'POS=R1' for the Click.)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
MuslimPerson
Posts: 5
Joined: Wed Mar 15, 2017 4:01 pm

Re: How to Get element Position ?!

Post by MuslimPerson » Thu Mar 16, 2017 1:56 pm

HI chivracq , firstly thanks for your replys ..
we don't care (and don't want to care) about your religious
i think you don't know the islam religion to say this , whatever the "Allah bless you" in the last of my comments are like = best regards , hope you in best case , etc ..

and there is no wrong thing in it , i don't talk about religions here , it's just simple words like i explained ..

whatever , it's not our subject ..

i want to : "EXTRACT THE POSITION OF (repaeated) ELEMENT ("same" in some attributes (like "class" in our example))"

Example:

Code: Select all

<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>
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to Get element Position ?!

Post by chivracq » Thu Mar 16, 2017 4:58 pm

MuslimPerson wrote:HI chivracq , firstly thanks for your replys ..
we don't care (and don't want to care) about your religious
i think you don't know the islam religion to say this , whatever the "Allah bless you" in the last of my comments are like = best regards , hope you in best case , etc ..

and there is no wrong thing in it , i don't talk about religions here , it's just simple words like i explained ..

whatever , it's not our subject ..
No comments... :roll:
MuslimPerson wrote:i want to : "EXTRACT THE POSITION OF (repaeated) ELEMENT ("same" in some attributes (like "class" in our example))"

Example:

Code: Select all

<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>
OK, so your Starting Point is "Text5", from which you can deduct "class1" if you don't know it already, using 'EXTRACT=HTM' + 'EVAL()'.

Then you need to do an 'EXTRACT=HTM' on the 'DIV' at a higher Level containing all your 'DIV's with "class1", using its Class for example directly if you already know it.
If you don't know it or don't know any Attributes to identify and tag that Containing 'DIV' directly, you will need to use "Double Relative Positioning" to tag some non-'DIV' HTML Element outside of the Containing 'DIV' (before or after it, it doesn't matter, whatever Element is easier to locate and more likely to be Unique), to then be able for iMacros to see and tag that Containing 'DIV'. (Search my Posts on "Double Relative Positioning" if you don't understand or want more Info about the Principe and find Code Examples...)

Once you've got the 'EXTRACT=HTM' Data on the Containing 'DIV', you use 'EVAL()' + 'match()' or 'split()' to find your Position Nb...! 8)

I don't like/use/know 'match()' so I'll elaborate on using 'split()', but pfff..., would be easier if you had posted the URL of your Page...
=> First, 'split()' on "Text5" will return 2 Strings, z[0] and z[1]. ('split()' returns an Array...)
=> Then, 'split()' on "class1" applied to 'z[0]' and the 'length()' Property (-1) of the Array returned by the 'split()' will give you your Pos_Nb.

This is one Solution, there are probably other ways...
Have a look at the following Thread where I applied/demonstrated this "Technique" on a DDLB to find out dynamically the Total Nb of Options in the DDLB. The Principle is the same...
- Re: Number of Options in a Select tag
The DDLB would be your Containing 'DIV' and the DDLB Options would be your 'class1' Elements.

Enjoy...! (And post your Final Script once you got it to work..., and/or if you get stuck somewhere...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
MuslimPerson
Posts: 5
Joined: Wed Mar 15, 2017 4:01 pm

Re: How to Get element Position ?!

Post by MuslimPerson » Thu Mar 16, 2017 8:49 pm

No comments... :roll:
Ok ! :roll:
Enjoy...! (And post your Final Script once you got it to work..., and/or if you get stuck somewhere...)
i resolved it by "for function" , but with javascript language help ..

my code: in (.js) file ..

Code: Select all

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)
}
}
Allah bless you. :wink:
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to Get element Position ?!

Post by chivracq » Thu Mar 16, 2017 9:24 pm

MuslimPerson wrote:
Enjoy...! (And post your Final Script once you got it to work..., and/or if you get stuck somewhere...)
i resolved it by "for function" , but with javascript language help ..

my code: in (.js) file ..

Code: Select all

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)
}
}
Allah bless you. :wink:
OK, Thanks for sharing your Solution, which is even more simple than mine, but will only work on FF while mine could be used for all Browsers...
Hum, and mine will probably run much quicker from POS>5 and would still take the same amount of time to execute if POS=100 or POS=1000 while yours would probably need more than 1 min to execute for POS=1000...
Doesn't really play a role in this Case for POS=10 (Max), but should be taken into Consideration for sbd who wanted to reuse it in other Circumstances for some other Site...

>>>

Further I've reported your Post to check with the Forum Admin how to "handle" you as a User on this Forum and your Posts as you keep including some religious Content in all your Posts even after I've asked you to stop that... :roll:
But I already know I probably won't try to help you in the future if you (are still allowed to) open any new Threads...
Last edited by chivracq on Thu Mar 16, 2017 9:45 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
MuslimPerson
Posts: 5
Joined: Wed Mar 15, 2017 4:01 pm

Re: How to Get element Position ?!

Post by MuslimPerson » Thu Mar 16, 2017 9:43 pm

But I already know I probably won't try to help you in the future if you (are still allowed to) open any new Threads...
Thanks in the future.. :roll:
Post Reply