Choosing between two identical elements

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
taxon_dev
Posts: 6
Joined: Tue Apr 13, 2021 3:06 pm

Choosing between two identical elements

Post by taxon_dev » Wed Apr 21, 2021 1:04 pm

Hi,
I'm using:
Imacros 12.6.505.4525
on WIndows 10 OS, and Explorer 20H2, and the Imacros for IE ofcourse.
The thing is I've two identical input elements, and the Imacros don't know how to access it.
I attach my code to this message below:

Code: Select all

VERSION BUILD=12.6.505.4525
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 1.00
URL GOTO=https://*************
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 10
SET !EXTRACT_TEST_POPUP NO
SET !DATASOURCE "{some csv path}"
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:***** CONTENT={{!COL1}}
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:k-input CONTENT={{!COL2}}
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:*****
WAIT SECONDS=2
'The element below is the element the Imacros software cannot access
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL3}}
WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=CLASS:"checkbox style-2 pull-right ng-untouched ng-valid ng-isolate-scope ng-dirty ng-valid-parse" CONTENT=YES
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL1}}
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:k-select
TAG POS=6 TYPE=LI ATTR=TXT:primary
TAG POS=3 TYPE=BUTTON ATTR=TXT:approve
WAIT SECONDS=2
TAG POS=4 TYPE=BUTTON ATTR=TXT:approve
TAG POS=1 TYPE=SPAN ATTR=CLASS:"k-icon k-i-arrow-60-down"
TAG POS=3 TYPE=LI ATTR=TXT:{{!COL5}}
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:mail CONTENT={{!COL6}}
WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:approve
'New tab opened
TAB T=2
I already tried to change the POS attribute to another absolute value (tried to change it to 2-5), and I've already tried to use the relative position but no success in this attempt as well (tried to write R0. R1, R2, R3 even tried R-1 since the element is from the left side and not the right side from the checkbox).
If someone have an insight about this, or solved something similar, it would be great.
Thanks a lot!
Last edited by taxon_dev on Sun Apr 25, 2021 9:26 am, edited 2 times in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choosing between two identical elements

Post by chivracq » Wed Apr 21, 2021 1:42 pm

taxon_dev wrote:
Wed Apr 21, 2021 1:04 pm
Hi,
I'm using:

Code: Select all

Imacros 12.6.505.4525
on WIndows 10 OS, and Explorer 20H2, and the Imacros for IE ofcourse.
The thing is I've two identical input elements, and the Imacros don't know how to access it.
I attach my code to this message below:

Code: Select all

VERSION BUILD=12.6.505.4525
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 1.00
URL GOTO=https://*************
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 10
SET !EXTRACT_TEST_POPUP NO
SET !DATASOURCE "{some csv path}"
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:yeshut CONTENT={{!COL1}}
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:k-input CONTENT={{!COL2}}
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:rbDarconRishayonTz
WAIT SECONDS=2
'The element below is the element the Imacros software cannot access
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL3}}
WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=CLASS:"checkbox style-2 pull-right ng-untouched ng-valid ng-isolate-scope ng-dirty ng-valid-parse" CONTENT=YES
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL1}}
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:k-select
TAG POS=6 TYPE=LI ATTR=TXT:primary
TAG POS=3 TYPE=BUTTON ATTR=TXT:approve
WAIT SECONDS=2
TAG POS=4 TYPE=BUTTON ATTR=TXT:approve
TAG POS=1 TYPE=SPAN ATTR=CLASS:"k-icon k-i-arrow-60-down"
TAG POS=3 TYPE=LI ATTR=TXT:{{!COL5}}
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:mail CONTENT={{!COL6}}
WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:approve
'New tab opened
TAB T=2
I already tried to change the POS attribute to another absolute value (tried to change it to 2-5), and I've already tried to use the relative position but no success in this attempt as well (tried to write R0. R1, R2, R3 even tried R-1 since the element is from the left side and not the right side from the checkbox).
If someone have an insight about this, or solved something similar, it would be great.
Thanks a lot!

Can you correct the Typo in your Thread Title...? :wink:
(I've corrected already in my Reply...)
EDIT: OK, done, Thanks... :D

>>>

Hum, OK, your Script looks "correct" to me..., then hum, concerning this TEXT 'INPUT' Field for '{{!COL3'}}', what "happens" at that Line...?
=> Do you get any Runtime Error that the Element cannot be found...?, or does your Script continue further...?
Or does maybe only the first Char of your '!COL3' String get input into the Field, as there seems to be some Validation on that Field...?

You need to deactivate '!ERRORIGNORE' for that Line, of course...:

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:yeshut CONTENT={{!COL1}}
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:k-input CONTENT={{!COL2}}
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:rbDarconRishayonTz
WAIT SECONDS=2
'>
'The element below is the element the Imacros software cannot access
'Debug:
SET !ERRORIGNORE NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL3}}
SET !ERRORIGNORE YES
WAIT SECONDS=2
PAUSE
'>
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
For "Element not found" or "the Script continues", then yep indeed, that will be related to finding the "correct" 'POS=n' or using 'Relative Positioning' like you mention and already tried...
But hum, I'm not "convinced" you tried to use 'R-POS' "correctly", as without specifying an 'Anchor', iMacros will use the previous 'TAG' Statement as 'Anchor' which will be on the "rbDarconRishayonTz" 'RadioButton' while you mention a "CheckBox" and I do see indeed some 'TAG' Statement on a 'CB' in your Script, but that Line is after the Line about the 'INPUT' Field... (And that is not correct...)

Maybe more reliable anyway for 'R-POS' would be to use the 'LABEL' Element corresponding to the 'INPUT' Element. :idea:

>

Then for "only 1 Char being input + Validation on the Field", then hum-hum..., maybe worth trying the 'EVENT' Mode then for that Field, as the 'EVENT' Mode is slower than the 'TAG' Mode and will hopefully allow for enough time for the Validation to run Char by Char...

What also sometimes happens is that the 'INPUT' Element will (dynamically) "change" after typing the 1st Char, you'll need to inspect the Source to find out if that could be the Case... (Then the 'EVENT' Mode also usually works "better" with that kind of HTML Structure/Design...)

>

Then, hum..., not much more I can tell you without being able to "play" with the Page myself to test and analyze how it "behaves"... :|

Oh...!, and "R0" is not a valid Value for 'R-POS'... :!:
(But with '!ERRORIGNORE', that Line will simply do nothing..., same with "TAG POS=0" also...)
- (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...
taxon_dev
Posts: 6
Joined: Tue Apr 13, 2021 3:06 pm

Re: Choosing between two identical elements

Post by taxon_dev » Thu Apr 22, 2021 10:39 am

Hi,
First of all thanks a lot for all of your advices :D .
So I deleted this line from the code:

Code: Select all

SET !ERRORIGNORE YES
and tried to set an anchor like this:

Code: Select all

TAG POS=2 TYPE=LABEL ATTR=CLASS:ng-binding

TAG POS=R1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched" CONTENT={{!COL3}}
No matter what I try I receive this error:

Code: Select all

Error -1300: Cannot find HTML element of type "INPUT:TEXT" with attribute(s) "CLASS:ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched".. Line 20: TAG POS=R1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched" CONTENT={{!COL3}}
So I guess it can't find the next input, no matter what I write in the POS section. Any idea what I can do from here? :?

Edit: I must say (may be it will help), the website is probably an angular project, so the code is being generated by a plug in or something

Edit: I found a solution thanks to your advice with setting the anchor and using the relative position. thanks again.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choosing between two identical elements

Post by chivracq » Thu Apr 22, 2021 2:43 pm

taxon_dev wrote:
Thu Apr 22, 2021 10:39 am
Hi,
First of all thanks a lot for all of your advices :D .
So I deleted this line from the code:

Code: Select all

SET !ERRORIGNORE YES
and tried to set an anchor like this:

Code: Select all

TAG POS=2 TYPE=LABEL ATTR=CLASS:ng-binding

TAG POS=R1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched" CONTENT={{!COL3}}
No matter what I try I receive this error:

Code: Select all

Error -1300: Cannot find HTML element of type "INPUT:TEXT" with attribute(s) "CLASS:ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched".. Line 20: TAG POS=R1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-pristine ng-valid ng-isolate-scope ng-valid-maxlength ng-touched" CONTENT={{!COL3}}
So I guess it can't find the next input, no matter what I write in the POS section. Any idea what I can do from here? :?

Edit: I must say (may be it will help), the website is probably an angular project, so the code is being generated by a plug in or something

Edit: I found a solution thanks to your advice with setting the anchor and using the relative position. thanks again.

Alright, OK, good to hear that you managed to get it to work... :D , maybe nice if you could post that Solution... :idea: , => using "POS=R-1" then I would think..., or "POS=1" for the 'Anchor', or maybe using "Double Relative Positioning"...
- (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...
taxon_dev
Posts: 6
Joined: Tue Apr 13, 2021 3:06 pm

Re: Choosing between two identical elements

Post by taxon_dev » Sun Apr 25, 2021 9:32 am

Actually, it is quite common the iMacros software doesn't write the element properly from the record.
My solution to this was to write the element before the element I want to access and set it as the anchor, and then then mention the next element POS as R1 or whatever.
something like:

Code: Select all

TAG POS=2 TYPE=LABEL ATTR=CLASS:ng-binding
TAG POS=R1 TYPE=INPUT:TEXT ATTR=NAME:"" CONTENT={{!COL3}}
It is important to note that all elements require an ATTR even if its empty.
Your advices worth alot, thank you very much for your support.
taxon_dev
Posts: 6
Joined: Tue Apr 13, 2021 3:06 pm

Re: Choosing between two identical elements

Post by taxon_dev » Sun Apr 25, 2021 4:01 pm

Hi,
One more issue (hopefully the last for this script, and I hope its ok I'm just replying to the same post, I don't mind open a new one),
I need that one of the POS on the elements will be dynamic, I tried to insert it from the csv file, and I tried to write an eval function in order to return the right position, but no matter what I do I receive this message:
Error -1300: Expected POS=<number> or POS=R<number> where <number> is a non-zero integer. Line 43: TAG POS="{{myVal}}" TYPE=LI ATTR=ID:"

This is my code:

Code: Select all

VERSION BUILD=12.6.505.4525
'TAB T=1
'TAB CLOSEALLOTHERS
SET !PLAYBACKDELAY 1.00
URL GOTO=https://*************
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 10
SET !EXTRACT_TEST_POPUP NO
SET !DATASOURCE "SOME\PATH.csv"
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:yeshut CONTENT={{!COL1}}
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:k-input CONTENT={{!COL2}}
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:SomeName
WAIT SECONDS=2
TAG POS=2 TYPE=LABEL ATTR=CLASS:ng-binding
TAG POS=R1 TYPE=INPUT:TEXT ATTR=NAME:"" CONTENT={{!COL3}}

WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:continue
WAIT SECONDS=2
TAG POS=1 TYPE=LABEL ATTR=CLASS:ng-binding

WAIT SECONDS=2
TAG POS=R2 TYPE=INPUT:TEXT ATTR=NAME:"" CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL1}}
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:k-select
TAG POS=1 TYPE=UL ATTR=CLASS:"k-list k-reset"
TAG POS=R1 TYPE=LI ATTR=ID:""
TAG POS=3 TYPE=BUTTON ATTR=TXT:approve
WAIT SECONDS=2
TAG POS=4 TYPE=BUTTON ATTR=TXT:aoorive
TAG POS=1 TYPE=SPAN ATTR=CLASS:"k-input ng-scope"

TAG POS=1 TYPE=LI ATTR=CLASS:"k-item ng-scope" CONTENT={{!COL4}}

TAG POS=1 TYPE=UL ATTR=CLASS:"k-list k-reset"
'this is my my condition that cause the error
SET myVal EVAL("var x =\"{{!COL5}}\"; if(x == 50) { 1; } else if(x == 51) { 2; } else if(x == 52) { 3; } else if(x == 3) { 4; } else if(x == 4) { 5; } else if(x == 5) { 6; } else if(x == 6) { 7; }")
TAG POS="{{myVal}}" TYPE=LI ATTR=ID:""
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:"ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-dirty ng-valid-parse" CONTENT={{!COL4}}
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:mail CONTENT={{!COL6}}
WAIT SECONDS=2
TAG POS=1 TYPE=BUTTON ATTR=TXT:save
'New tab opened
'TAB T=2
Edit: may be I should add else? or choose the value by the content?
Thanks again.
Post Reply