Find POS Based on Text?

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
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
viking
Posts: 243
Joined: Sun Mar 16, 2008 7:22 am

Find POS Based on Text?

Post by viking » Mon Nov 11, 2019 1:10 am

I am getting rusty with iMacros.... :(

I have macros that contain commands like this:

Code: Select all

TAG POS=14 TYPE=INPUT:RADIO FORM=ACTION:asv/reload ATTR=NAME:ppw-instrumentRowSelection 
It selects the radio button the 14th row position. The position may change from day to day.
However, each such row on the web page has unique text, for example " *ending in 5234 " (where * is a wild card)
Is there some way to find the position based on the unique text and put this in a variable, e.g !VAR1
I could then use:

Code: Select all

TAG POS={{!VAR1}} TYPE=INPUT:RADIO FORM=ACTION:asv/reload ATTR=NAME:ppw-instrumentRowSelection 
instead.

p.s. Maybe the only way is to use a javescript loop and search through all TAGs until it finds it?

iMacros v8.9.7
Firefox v52.8.1
WIN7 x64
Last edited by viking on Mon Nov 11, 2019 5:19 am, edited 1 time in total.
chivracq
Posts: 9311
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Find POS Based on Text?

Post by chivracq » Mon Nov 11, 2019 3:46 am

viking wrote:
Mon Nov 11, 2019 1:10 am
I am getting rusty with iMacros.... :(

I have macros that contain commands like this:

Code: Select all

TAG POS=14 TYPE=INPUT:RADIO FORM=ACTION:asv/reload ATTR=NAME:ppw-instrumentRowSelection 
It selects the radio button the 14th row position. The position may change from day to day.
However, each such row on the web page has unique text, for example " *ending in 5234 " (where * is a wild card)
Is there some way to find the position based on the unique text and put this in a variable, e.g !VAR1
I could then use:

Code: Select all

TAG POS={{!VAR1}} TYPE=INPUT:RADIO FORM=ACTION:asv/reload ATTR=NAME:ppw-instrumentRowSelection 
instead.

p.s. Maybe the only way is to use a javescript loop and search through all TAGs until it finds it?

FCIM...! :|
Read the Forum Rules (again), your Sig is not the place for your FCI (if it's ueberhaupt your current FCI...!? :? ), as it's only confusing.... :roll:

+ Your Thread has probably nothing specific to FF, correct Sub-Forum was the 'General' one for this one, I would think... :roll:

Quick Reading, but Answer to your Qt is "yep, always possible", but it's probably not the "correct" Qt/Approach, nor is your "jav[e/a]script loop and search through all TAGs" either, there is/are probably some "easier" Sol(s)... :idea:

Your "JavaScript Loop/Search" Method is pretty cumbersome in my Opinion btw, the same Functionality can be done in 2 Lines in pure '.iim'... (and also works therefore in all Browsers/Versions...). :shock:
Last edited by chivracq on Mon Nov 11, 2019 5:34 am, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
viking
Posts: 243
Joined: Sun Mar 16, 2008 7:22 am

Re: Find POS Based on Text?

Post by viking » Mon Nov 11, 2019 5:33 am

chivracq wrote:
Mon Nov 11, 2019 3:46 am
FCIM...! :|
Read the Forum Rules (again), your Sig is not the place for your FCI (if it's ueberhaupt your current FCI...!? :? ), as it's only confusing.... :roll:
OK.. Moved the FCI away from the signature.
chivracq wrote:
Mon Nov 11, 2019 3:46 am
Quick Reading, but Answer to your Qt is "yep, always possible", but it's probably not the "correct" Qt/Approach, nor is your "jav[e/a]script loop and search through all TAGs" either, there is/are probably some "easier" Sol(s)... :idea:
Any "easier" Sol(s) would be most appreciated :D !

p.s. I was 99% sure that you would be the one responding to my post :wink:, but not at this time of the night! It must have been very early - or late for you (depending on when you go to sleep, and if you are currently in the NL).
chivracq
Posts: 9311
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Find POS Based on Text?

Post by chivracq » Mon Nov 11, 2019 5:56 am

viking wrote:
Mon Nov 11, 2019 5:33 am
chivracq wrote:
Mon Nov 11, 2019 3:46 am
FCIM...! :|
Read the Forum Rules (again), your Sig is not the place for your FCI (if it's ueberhaupt your current FCI...!? :? ), as it's only confusing.... :roll:
OK.. Moved the FCI away from the signature.

Ah OK, so that was the "correct" one...:

Code: Select all

iMacros v8.9.7
Firefox v52.8.1
WIN7 x64
But yep, FCI in Sig has "no Use", it is only confusing, or you still need to hard-code it in your OP when you open a Thread, + mention some "Last Edit + Date" if you absolutely want to mention it your Sig...

>>>
viking wrote:
Mon Nov 11, 2019 5:33 am
chivracq wrote:
Mon Nov 11, 2019 3:46 am
Quick Reading, but Answer to your Qt is "yep, always possible", but it's probably not the "correct" Qt/Approach, nor is your "jav[e/a]script loop and search through all TAGs" either, there is/are probably some "easier" Sol(s)... :idea:
Any "easier" Sol(s) would be most appreciated :D !

p.s. I was 99% sure that you would be the one responding to my post :wink:, but not at this time of the night! It must have been very early - or late for you (depending on when you go to sleep, and if you are currently in the NL).

Yep, still in NL, ah-ah...!, but I'm a DJ IRL, so I don't really follow a "Life-Rythm" to "work" from 09h-17h, ah-ah...!, especially in the WE's... :shock:

But OK, back to your Qt..., well, your "POS=14" is "not best" indeed, that's pretty high, and not very "reliable"...

But hum, your "NAME:ppw-instrumentRowSelection", is that the Name of the overall Radio Selection, of just the Name of that one Item within the whole RB...? (But then I wouldn't understand why they all have the same "ppw-instrumentRowSelection" Name... :? )

But anyway, the one Item you want to select very probably has a (Text) Label associated with it, that if you simply click on it will probably also automatically select the correct/corresponding RB-Item.
=> iMacros will record 2 Lines, one for the 'LABEL' and one for the 'RADIO' Element, if the 'RADIO' Element has "POS=14" or such a high Nb, you can comment it out and only keep the 'TAG' on the 'LABEL', that should do "the Trick" already... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
viking
Posts: 243
Joined: Sun Mar 16, 2008 7:22 am

Re: Find POS Based on Text?

Post by viking » Mon Nov 11, 2019 6:23 am

chivracq wrote:
Mon Nov 11, 2019 5:56 am
But OK, back to your Qt..., well, your "POS=14" is "not best" indeed, that's pretty high, and not very "reliable"...

But hum, your "NAME:ppw-instrumentRowSelection", is that the Name of the overall Radio Selection, of just the Name of that one Item within the whole RB...? (But then I wouldn't understand why they all have the same "ppw-instrumentRowSelection" Name... :? )

But anyway, the one Item you want to select very probably has a (Text) Label associated with it, that if you simply click on it will probably also automatically select the correct RB-Item.
=> iMacros will record 2 Lines, one for the 'LABEL' and one for the 'RADIO' Element, if the 'RADIO' Element has "POS=14" or such a high Nb, you can comment it out and only keep the 'TAG' on the 'LABEL', that should do "the Trick" already... :idea:
Ahh... such an easy solution!
Thanks as always :D !

It worked after modification. Only one line was recorded when clicking the label though. The relevant recorded macro was:

Code: Select all

URL GOTO=https://www.xxx.com
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
The problem with running this is that another row is automatically selected by default, and while the page is loading, the TAG command is ignored (not sure exactly why).
However, the following two "workarounds" work:

Code: Select all

URL GOTO=https://www.xxx.com
PAUSE
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
or

Code: Select all

URL GOTO=https://www.xxx.com
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
The second option is better as I don't have to manually wait for the page to finish loading.
(but kind of weird that it works :? )
chivracq
Posts: 9311
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Find POS Based on Text?

Post by chivracq » Mon Nov 11, 2019 6:50 am

viking wrote:
Mon Nov 11, 2019 6:23 am
Ahh... such an easy solution!
Thanks as always :D !

It worked after modification. Only one line was recorded when clicking the label though. The relevant recorded macro was:

Code: Select all

URL GOTO=https://www.xxx.com
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
The problem with running this is that another row is automatically selected by default, and while the page is loading, the TAG command is ignored (not sure exactly why).
However, the following two "workarounds" work:

Code: Select all

URL GOTO=https://www.xxx.com
PAUSE
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
or

Code: Select all

URL GOTO=https://www.xxx.com
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
TAG POS=1 TYPE=SPAN ATTR=TXT:ending<SP>in<SP>5234
The second option is better as I don't have to manually wait for the page to finish loading.
(but kind of weird that it works :? )

Yep, OK, good-good...! :D

I am a little bit surprised by the 'SPAN' Element in your Script(s), I would have rather expected a 'LABEL' Element (+ 2 Lines recorded), but OK, I might be "confusing" a bit with 'CheckBox' Elements (which usually work a bit the same), and last time I did some Testing on some RB was from monthssss ago, or maybe even 2 years ago, so I would have needed the whole HTML Structure of your Page/RB Element to be "more precise" if my previous Indications had not worked, and you would then have needed to use 'R-POS' or maybe 'Double R-POS' with a Check on first/last Item within the RB Element to dictate the Direction for 'Double R-POS', but that was luckily not needed... 8)

=> Or "we" would have gone back to your 'POS=14', that can be deducted indeed directly from some 'EXTRACT', I use a similar Technique in one of my Scripts on a 'DIV' with about 1400/1500 Elements in it to find "directly" and "unfailingly" the "correct" 'POS', + different Counts on how many Elements from those 1400/1500 meet certain Criteria..., but that was not needed in your Case... :D
And the Technique I use takes about 2-3 full Seconds (for 1400/1500 Elements, it would be instantaneous for 14/20 Elements), in just 2 Lines in pure '.iim' while it would take about several Minutes in '.js' to loop through all Elements... :shock:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply