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.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

How to Get element Position ?!

by MuslimPerson on Wed Mar 15, 2017 9:39 am

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....
MuslimPerson
 
Posts: 5
Joined: Wed Mar 15, 2017 9:01 am

Re: How to Get element Position ?!

by chivracq on Wed Mar 15, 2017 12: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6481
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to Get element Position ?!

by MuslimPerson on Thu Mar 16, 2017 6:56 am

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>
MuslimPerson
 
Posts: 5
Joined: Wed Mar 15, 2017 9:01 am

Re: How to Get element Position ?!

by chivracq on Thu Mar 16, 2017 9:58 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6481
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to Get element Position ?!

by MuslimPerson on Thu Mar 16, 2017 1: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:
MuslimPerson
 
Posts: 5
Joined: Wed Mar 15, 2017 9:01 am

Re: How to Get element Position ?!

by chivracq on Thu Mar 16, 2017 2: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 2:45 pm, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6481
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to Get element Position ?!

by MuslimPerson on Thu Mar 16, 2017 2: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:
MuslimPerson
 
Posts: 5
Joined: Wed Mar 15, 2017 9:01 am


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 7 guests

-->