Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

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
davinb
Posts: 4
Joined: Wed Jan 26, 2022 2:38 pm

Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by davinb » Wed Jan 26, 2022 8:30 pm

Code: Select all

iMacros 2021 Enterprise x64 bits
PC Windows 8.1 Portuguese/BR


Hello, forum! This is my first post, I apologize if I make a mistake about any rule that I didn't understand and I ask that you consider please to being patient with a new lay user who started using this imacros language a few days ago.

:arrow: The scenario of the logic problem to automate the Html restaurant delivery game: It will be a page of a puzzle that I will develop for simulations of a game with random results that needs to match the "order" with the "food" to regarding one of the 3 choices.

First: i will need to choose one of three choices(the customer).

Second: a word with food's name will appear and then i need to choose the correct image with the picture of this word.

Third: Validate on the last button.

:arrow: In this puzzle, will have a total of 11 images (Radio buttons) are shuffled and a word from one of these 11 images appears, each one with an ID. I need to click on the correct image (Radio button) that refers the word, to validate the correspondent demand, each right confirmation gives xp.

:arrow: I don't have the url of my game available yet, it's just a matter of conditional logic to learning for those starting out.

Question: Select the desired alternative and then select the image of the random word.

Example:

:arrow: "Select the image (some of the 11 assorted images in few amount) that matches the word "soup" and then "Confirm", then appears images like "soda, cake, soup, cookie".

:arrow: The correct on is in Position 3 (horizontally), but it could be in any position, so i need to find, validate and use this text "soup" as an anchor/key to create the condition to execute the specific click on the correct image for automatic select the position and the radio:input by the specific id number of the image based on text "soup", ignoring others radiobuttons macros and focusing only on the word that appears and the image, ignoring other possibilities.

Limitations/difficulties:

:arrow: I don't believe that !VAR can solve it, because I will need to work with many amounts of images, more than 10.

:arrow: The positions of the images will alternate and I don't know how to indicate in POS=?.

Again, sorry for my ignorance, I imagine i'm completely lost and I don't know where to go. I swear there are days I tried to understand some logic it on my own both on the wiki and on the forum, but nothing was clear enough for my limitation. :oops:

HTML Layout Example:

Image

I'm trying to deduce how to develop the following code with what i've found, but insecure about create click conditions on one of 11 random images based on a single random word out of 11 too:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0 

'Select customer (ok here)'
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:100

'list to match the unique word that appear with one of the correct image'

'if find the word soda, then find the position of the image of the soda recognized by html id, "idword1", and ignore the others macros.'
SET Forward_To "soda"
TAG POS=1  TYPE=B ATTR=soda
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}* 
TAG POS=? TYPE=RADIO:INPUT FORM=ID:demo-form ATTR=ID:word1

'if find the word barbecue, then find the position of the image of the barbecue recognized by html id, id "word2", and ignore the others macros.'
SET Forward_To "barbecue" 
TAG POS=1 TYPE=B ATTR=TXT:barbecue
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word2

'if find the word pie, then find the position of the image of the pie recognized by html id, id "word3", and ignore the others macros.'
SET Forward_To "pie"
TAG POS=1 TYPE=B ATTR=TXT:pie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word3

'if find the word noodle, then find the position of the image of the noodle recognized by html id, id "word4", and ignore the others macros.'
SET Forward_To "noodle" 
TAG POS=1 TYPE=B ATTR=TXT:noodle
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word4

'if find the word soup, then find the position of the image of the soup recognized by html id, id "word5", and ignore the others macros.'
SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word5

'if find the word bread, then find the position of the image of the bread recognized by html id, id "word6", and ignore the others macros.'
SET Forward_To "bread"
TAG POS=1 TYPE=B ATTR=TXT:bread
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word6

'if find the word hotdog, then find the position of the image of the hotdog recognized by html id, id "word7", and ignore the others macros.'
SET Forward_To "hotdog"
TAG POS=1 TYPE=B ATTR=TXT:hotdog
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word7

'if find the word sandwich, then find the position of the image of the sandwich recognized by html id, id "word8", and ignore the others macros.'
SET Forward_To "sandwich"
TAG TYPE=B ATTR=TXT:sandwich
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS= ? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word8

'if find the word icecream, then find the position of the image of the icecream recognized by html id, id "word9", and ignore the others macros.'
SET Forward_To "icecream"
TAG POS=1 TYPE=B ATTR=TXT:icecream
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word9

'if find the word cake, then find the position of the image of the cake recognized by html id, id "word10", and ignore the others macros.'
SET Forward_To "cake" 
TAG POS=1 TYPE=B ATTR=TXT:cake
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word10

''if find the word cookie, then find the position of the image of the cookie recognized by html id, id "word11", and ignore the others macros.'
SET Forward_To "cookie" 
TAG POS=1 TYPE=B ATTR=TXT:cookie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word11

'ok here too, the final confirmation'
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:demo-form ATTR=ID:submit
Please someone help me with this logic I'm trying to develop. :?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by chivracq » Thu Jan 27, 2022 12:10 am

davinb wrote:
Wed Jan 26, 2022 8:30 pm

Code: Select all

iMacros 2021 Enterprise x64 bits
PC Windows 8.1 Portuguese/BR


Hello, forum! This is my first post, I apologize if I make a mistake about any rule that I didn't understand and I ask that you consider please to being patient with a new lay user who started using this imacros language a few days ago.

:arrow: The scenario of the logic problem to automate the Html restaurant delivery game: It will be a page of a puzzle that I will develop for simulations of a game with random results that needs to match the "order" with the "food" to regarding one of the 3 choices.

First: i will need to choose one of three choices(the customer).

Second: a word with food's name will appear and then i need to choose the correct image with the picture of this word.

Third: Validate on the last button.

:arrow: In this puzzle, will have a total of 11 images (Radio buttons) are shuffled and a word from one of these 11 images appears, each one with an ID. I need to click on the correct image (Radio button) that refers the word, to validate the correspondent demand, each right confirmation gives xp.

:arrow: I don't have the url of my game available yet, it's just a matter of conditional logic to learning for those starting out.

Question: Select the desired alternative and then select the image of the random word.

Example:

:arrow: "Select the image (some of the 11 assorted images in few amount) that matches the word "soup" and then "Confirm", then appears images like "soda, cake, soup, cookie".

:arrow: The correct on is in Position 3 (horizontally), but it could be in any position, so i need to find, validate and use this text "soup" as an anchor/key to create the condition to execute the specific click on the correct image for automatic select the position and the radio:input by the specific id number of the image based on text "soup", ignoring others radiobuttons macros and focusing only on the word that appears and the image, ignoring other possibilities.

Limitations/difficulties:

:arrow: I don't believe that !VAR can solve it, because I will need to work with many amounts of images, more than 10.

:arrow: The positions of the images will alternate and I don't know how to indicate in POS=?.

Again, sorry for my ignorance, I imagine i'm completely lost and I don't know where to go. I swear there are days I tried to understand some logic it on my own both on the wiki and on the forum, but nothing was clear enough for my limitation. :oops:

HTML Layout Example:

Code: Select all

[img]https://i.imgur.com/TDCcNLx.png[/img]
I'm trying to deduce how to develop the following code with what i've found, but insecure about create click conditions on one of 11 random images based on a single random word out of 11 too:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0 

'Select customer (ok here)'
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:100

'list to match the unique word that appear with one of the correct image'

'if find the word soda, then find the position of the image of the soda recognized by html id, "idword1", and ignore the others macros.'
SET Forward_To "soda"
TAG POS=1  TYPE=B ATTR=soda
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}* 
TAG POS=? TYPE=RADIO:INPUT FORM=ID:demo-form ATTR=ID:word1

'if find the word barbecue, then find the position of the image of the barbecue recognized by html id, id "word2", and ignore the others macros.'
SET Forward_To "barbecue" 
TAG POS=1 TYPE=B ATTR=TXT:barbecue
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word2

'if find the word pie, then find the position of the image of the pie recognized by html id, id "word3", and ignore the others macros.'
SET Forward_To "pie"
TAG POS=1 TYPE=B ATTR=TXT:pie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word3

'if find the word noodle, then find the position of the image of the noodle recognized by html id, id "word4", and ignore the others macros.'
SET Forward_To "noodle" 
TAG POS=1 TYPE=B ATTR=TXT:noodle
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word4

'if find the word soup, then find the position of the image of the soup recognized by html id, id "word5", and ignore the others macros.'
SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word5

'if find the word bread, then find the position of the image of the bread recognized by html id, id "word6", and ignore the others macros.'
SET Forward_To "bread"
TAG POS=1 TYPE=B ATTR=TXT:bread
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word6

'if find the word hotdog, then find the position of the image of the hotdog recognized by html id, id "word7", and ignore the others macros.'
SET Forward_To "hotdog"
TAG POS=1 TYPE=B ATTR=TXT:hotdog
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word7

'if find the word sandwich, then find the position of the image of the sandwich recognized by html id, id "word8", and ignore the others macros.'
SET Forward_To "sandwich"
TAG TYPE=B ATTR=TXT:sandwich
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS= ? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word8

'if find the word icecream, then find the position of the image of the icecream recognized by html id, id "word9", and ignore the others macros.'
SET Forward_To "icecream"
TAG POS=1 TYPE=B ATTR=TXT:icecream
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word9

'if find the word cake, then find the position of the image of the cake recognized by html id, id "word10", and ignore the others macros.'
SET Forward_To "cake" 
TAG POS=1 TYPE=B ATTR=TXT:cake
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word10

''if find the word cookie, then find the position of the image of the cookie recognized by html id, id "word11", and ignore the others macros.'
SET Forward_To "cookie" 
TAG POS=1 TYPE=B ATTR=TXT:cookie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word11

'ok here too, the final confirmation'
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:demo-form ATTR=ID:submit
Please someone help me with this logic I'm trying to develop. :?

Okay..., I'm not sure I understand the whole Scenario exactly, that's a bit difficult only from your Explanation in Text and your Script, "easier" would be if I could have a look at the Site myself to understand "the Logic" and the Behaviour... :(
But maybe some Screenshot(s) would already help a bit...? :idea:
:arrow: To be uploaded directly to the Forum, like explained in the Forum Rules... :!:
=> Can you also (re-)upload your Screenshot from 'imgur'...?, I can't see it anyway, the Site doesn't work anymore in my Browser... :|

EDIT: Done myself... :roll:
... And correct URL was:

Code: Select all

https://i.imgur.com/TDCcNLxh.jpg
davinb_#1.jpg

>>>

But anyway, I think you can probably fairly easily code/implement the Logic that you want using 'Relative Positioning'... :idea:
=> Have a look at the following Thread where I had explained several Techniques that I use in pure '.iim' for Conditional Logic/Behaviour...:
- Workarounds for Conditional Logic in Macro Code

If you can use 'R-POS', that would be the "easiest", otherwise, `EXTRACT` + `EVAL()` is "the Way to go", and you might need to still use the `EXTRACT` Mechanism anyway to extract the "corresponding" Word..., and maybe with several Levels of 'R-POS'... :twisted:

And as you are using iMB v2021, and you mention Images, maybe using the `IMAGESEARCH` Command/Functionality might also be an Option to explore... :idea:
- (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...
davinb
Posts: 4
Joined: Wed Jan 26, 2022 2:38 pm

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by davinb » Thu Jan 27, 2022 3:02 am

chivracq wrote:
Thu Jan 27, 2022 12:10 am
Okay..., I'm not sure I understand the whole Scenario exactly, that's a bit difficult only from your Explanation in Text and your Script, "easier" would be if I could have a look at the Site myself to understand "the Logic" and the Behaviour... :(
But maybe some Screenshot(s) would already help a bit...? :idea:
:arrow: To be uploaded directly to the Forum, like explained in the Forum Rules... :!:
=> Can you also (re-)upload your Screenshot from 'imgur'...?, I can't see it anyway, the Site doesn't work anymore in my Browser... :|

But anyway, I think you can probably fairly easily code/implement the Logic that you want using 'Relative Positioning'... :idea:
=> Have a look at the following Thread where I had explained several Techniques that I use in pure '.iim' for Conditional Logic/Behaviour...:
- Workarounds for Conditional Logic in Macro Code

If you can use 'R-POS', that would be the "easiest", otherwise, `EXTRACT` + `EVAL()` is "the Way to go", and you might need to still use the `EXTRACT` Mechanism anyway to extract the "corresponding" Word..., and maybe with several Levels of 'R-POS'... :twisted:

And as you are using iMB v2021, and you mention Images, maybe using the `IMAGESEARCH` Command/Functionality might also be an Option to explore... :idea:
Yeeeep, the master chivracq answered me :D

:oops: Sorry about the image I forgot to post for everyone to see, I thought the link was enough. Here it is :arrow: : https://imgur.com/gallery/Ok2gCh3 :!:
,and sorry about my english too.

:P And thank you! Actually, I'm really glad you answered me, because i've always saw you answering most questions when I was looking and I was amazed at how proactive you are. I really prefer '.iim' than '.js', for me, just starting out, it seems to be more accessible and yes, i will try based on yours instructions tagged here and i will give some feedback.

:| Maybe now checking the image you can give me a clearer path, because I don't know how I would use relative positions if the positions change randomly. And I don't know how to use Eval with extract. It didn't work for me, I really get confused and don't understand how to apply following a specific command. If you could give me the example in two command lines I would be very grateful. I try, but i know this is just wrong in some way:

Code: Select all

SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup EXTRACT=TXT
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG R-POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word5 EXTRACT=EVAL("soup")


My extract, which I surely don't know how to use, didn't work and the R-POS ? which position? I didn't want to put, I wanted to automatically identify with the id of the radio button. :cry:

:? Another question is also about words with different characters that iMacros may not identify. Because I intended to make a version in Portuguese, and for example, "bean" is written with the accent "feijão" I don't know if that would be identifiable.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by chivracq » Thu Jan 27, 2022 12:43 pm

davinb wrote:
Thu Jan 27, 2022 3:02 am
Yeeeep, the master chivracq answered me :D

:oops: Sorry about the image I forgot to post for everyone to see, I thought the link was enough. Here it is :arrow: : https://imgur.com/gallery/Ok2gCh3 :!:
,and sorry about my english too.

Yeah, well, your English is correct, that's not "an Issue"...

About Screenshots, "we" want them uploaded directly to the Forum, all those external Pix Hosting Sites all go dark/commercial "one day" or do some "Cleaning" from time to time and those Screenshots then just become some dead Links, + I've blocked most of them myself actually, well except 'imgur' because also used on 'SOF' ('Stack Overflow' Site/Forum), but 'imgur' has become a complete PITA since about 1 year and doesn't work anymore in any of the Browsers I use myself (PM26 + FF55), (I only get/see a blank (Black) Page with no Content "visible", or I need to mentally decipher/render the HTML-Source myself)...

But OK, I managed to find the/some "correct" URL from that Source (=> the 'twitter:image' URL) and to re-upload that Image myself to the Thread (in my previous Post)... :|

>>>
davinb wrote:
Thu Jan 27, 2022 3:02 am
:P And thank you! Actually, I'm really glad you answered me, because i've always saw you answering most questions when I was looking and I was amazed at how proactive you are. I really prefer '.iim' than '.js', for me, just starting out, it seems to be more accessible and yes, i will try based on yours instructions tagged here and i will give some feedback.

:| Maybe now checking the image you can give me a clearer path, because I don't know how I would use relative positions if the positions change randomly. And I don't know how to use Eval with extract. It didn't work for me, I really get confused and don't understand how to apply following a specific command. If you could give me the example in two command lines I would be very grateful. I try, but i know this is just wrong in some way:

Code: Select all

SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup EXTRACT=TXT
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG R-POS=? TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:word5 EXTRACT=EVAL("soup")


My extract, which I surely don't know how to use, didn't work and the R-POS ? which position? I didn't want to put, I wanted to automatically identify with the id of the radio button. :cry:

Hum, then OK, from that Screenshot, yep-yep, I now understand the Scenario/Workflow "a bit better", ah-ah...!, and hum, it's actually even "simpler" that I thought, you won't even really need 'R-POS'...

=> All you'll need to hard-code in your Script will be "1"/"2"/"3" for the "Customer #" RB (RadioButton), then extract the "Customer # is ordering: xxx" to extract or isolate that "xxx" (=> = "soup" in your Example) to reuse to select the "corresponding" Image from the horizontal RB with the 6 Images.

If (the String) "soup" is used "somewhere" for that RB (for 'ID' / 'Name' / 'ALT' / 'TITLE' / somewhere in the Filename or Path for the 'HREF' of the Image / etc...), then that's it, you're done...!, it will be trivial to use/reuse that "soup" String to select the "correct" RB-Option... :P
(... And hopefully that Mechanism will work for all other Terms/Images/Strings, not only "soup", but "soda" / "cake" / whatever...!)
If "soup" is nowhere to find, then you'll need to find/construct a "Mapping" between each Image and some Attribute(s) for those Images to the Meaning of the corresponding Word, (=> is "word5" for example always used for "soup"...?), and maybe to "train" your System and extend the Mapping as/if new Images/Words come up...

But even if the URL's are completely random/dynamic, it's always possible to differentiate the Images, is it at the Byte-Size of the "physical" File (saved locally) or even checking the first 10 or 100 Chars in the File (from 'Notepad' or equivalent), iMacros can do that...
... Or again, use `IMAGESEARCH`, but you'll also have to "train" that System, and `IMAGEX/Y` would already contain the Coordinates of the Image to click in the horizontal RB (using the `DS` Mode or a "slow" Click using the `EVENT` Mode and a mini-`MOUSEMOVE` Statement, that will both use Coordinates, or using `EVAL()` to calculate/deduct empirically the 'POS=n' in the RB based on those Coordinates...

For all those Suggs/Explanation(s) of mine, I would need to be able to look at the HTML-Structure of the Page, in order to be more "precise", to see what can be used, what is "changing" and what "remains constant" with different Scenarios..., => can you maybe upload (a full) 'HTML Saveas' of the Page to your Thread...? (Zipped, Max 256Kb), => or only HTML without the Images if the '.zip' becomes larger than 256Kb, but I won't be able to check/compare the Size of the Images... :idea:
And "ideally" maybe 3 Examples, like "Cust_1 + soup" + "Cust_2 + soda" + "Cust_3 + cake", ah-ah...!, hum, or "Cust_3 + soup" also, in case I need to find Differences at the 'HREF' Level), but 1 Example would already give me much more "Insight"...

>>>
davinb wrote:
Thu Jan 27, 2022 3:02 am
:? Another question is also about words with different characters that iMacros may not identify. Because I intended to make a version in Portuguese, and for example, "bean" is written with the accent "feijão" I don't know if that would be identifiable.

Nope, shouldn't play a Role, iMacros uses 'UTF-8' Char Encoding, (and at the Browser Level actually, or the Char Encoding used on the Web-Server), you can use Russian and Chinese Chars also if you want..., your Beans are "safe" in all Languages, ah-ah...! :wink: :P 8)
- (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...
davinb
Posts: 4
Joined: Wed Jan 26, 2022 2:38 pm

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by davinb » Sun Jan 30, 2022 4:44 pm

chivracq wrote:
Thu Jan 27, 2022 12:43 pm

Yeah, well, your English is correct, that's not "an Issue"...

About Screenshots, "we" want them uploaded directly to the Forum, all those external Pix Hosting Sites all go dark/commercial "one day" or do some "Cleaning" from time to time and those Screenshots then just become some dead Links, + I've blocked most of them myself actually, well except 'imgur' because also used on 'SOF' ('Stack Overflow' Site/Forum), but 'imgur' has become a complete PITA since about 1 year and doesn't work anymore in any of the Browsers I use myself (PM26 + FF55), (I only get/see a blank (Black) Page with no Content "visible", or I need to mentally decipher/render the HTML-Source myself)...

But OK, I managed to find the/some "correct" URL from that Source (=> the 'twitter:image' URL) and to re-upload that Image myself to the Thread (in my previous Post)... :|

Hum, then OK, from that Screenshot, yep-yep, I now understand the Scenario/Workflow "a bit better", ah-ah...!, and hum, it's actually even "simpler" that I thought, you won't even really need 'R-POS'...

=> All you'll need to hard-code in your Script will be "1"/"2"/"3" for the "Customer #" RB (RadioButton), then extract the "Customer # is ordering: xxx" to extract or isolate that "xxx" (=> = "soup" in your Example) to reuse to select the "corresponding" Image from the horizontal RB with the 6 Images.

If (the String) "soup" is used "somewhere" for that RB (for 'ID' / 'Name' / 'ALT' / 'TITLE' / somewhere in the Filename or Path for the 'HREF' of the Image / etc...), then that's it, you're done...!, it will be trivial to use/reuse that "soup" String to select the "correct" RB-Option... :P
(... And hopefully that Mechanism will work for all other Terms/Images/Strings, not only "soup", but "soda" / "cake" / whatever...!)
If "soup" is nowhere to find, then you'll need to find/construct a "Mapping" between each Image and some Attribute(s) for those Images to the Meaning of the corresponding Word, (=> is "word5" for example always used for "soup"...?), and maybe to "train" your System and extend the Mapping as/if new Images/Words come up...

But even if the URL's are completely random/dynamic, it's always possible to differentiate the Images, is it at the Byte-Size of the "physical" File (saved locally) or even checking the first 10 or 100 Chars in the File (from 'Notepad' or equivalent), iMacros can do that...
... Or again, use `IMAGESEARCH`, but you'll also have to "train" that System, and `IMAGEX/Y` would already contain the Coordinates of the Image to click in the horizontal RB (using the `DS` Mode or a "slow" Click using the `EVENT` Mode and a mini-`MOUSEMOVE` Statement, that will both use Coordinates, or using `EVAL()` to calculate/deduct empirically the 'POS=n' in the RB based on those Coordinates...

For all those Suggs/Explanation(s) of mine, I would need to be able to look at the HTML-Structure of the Page, in order to be more "precise", to see what can be used, what is "changing" and what "remains constant" with different Scenarios..., => can you maybe upload (a full) 'HTML Saveas' of the Page to your Thread...? (Zipped, Max 256Kb), => or only HTML without the Images if the '.zip' becomes larger than 256Kb, but I won't be able to check/compare the Size of the Images... :idea:
And "ideally" maybe 3 Examples, like "Cust_1 + soup" + "Cust_2 + soda" + "Cust_3 + cake", ah-ah...!, hum, or "Cust_3 + soup" also, in case I need to find Differences at the 'HREF' Level), but 1 Example would already give me much more "Insight"...

Nope, shouldn't play a Role, iMacros uses 'UTF-8' Char Encoding, (and at the Browser Level actually, or the Char Encoding used on the Web-Server), you can use Russian and Chinese Chars also if you want..., your Beans are "safe" in all Languages, ah-ah...! :wink: :P 8)
Hi, thanks for helping me and sorry for the delay in getting back to you, I've had an intense week.

The html is still under development, so I can only send a static example of an option.

Here is the zipped html:

https://www.dropbox.com/s/7rsvva7k4n7ji ... e.zip?dl=0

My problem is that the last command is selecting what appears on the page and not just the text item ignoring other options.

I really can't know how to do hard code, if you could give me an example by formatting the code it would help me a lot, speaking like this I can't interpret it I'm new to this all I'm trying to learn html too, just starting in this universe.

The command is to identify the text item that appears in "Customer 1 is ordering: item" and based on it, associate this item text with an id of the radio button to be clicked after validating this item text.

Sorry for my lack of knowledge and thank you very much for helping me, if you can give me a code path so that I can understand the structure I will be very grateful.

Current macro:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0 

'Select customer (ok here)'
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:100

'list to match the unique word that appear with one of the correct image'

'if find the word soda, then find the position of the image of the soda recognized by html id, "idword1", and ignore the others macros.'
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:10

SET Forward_To "soda"
TAG POS=1  TYPE=B ATTR=soda
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}* 
TAG POS=1 TYPE=RADIO:INPUT ATTR=ID:word6

'if find the word barbecue, then find the position of the image of the barbecue recognized by html id, id "word2", and ignore the others macros.'
SET Forward_To "barbecue" 
TAG POS=1 TYPE=B ATTR=TXT:barbecue
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word7

'if find the word pie, then find the position of the image of the pie recognized by html id, id "word3", and ignore the others macros.'
SET Forward_To "pie"
TAG POS=1 TYPE=B ATTR=TXT:pie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word11

'if find the word noodle, then find the position of the image of the noodle recognized by html id, id "word4", and ignore the others macros.'
SET Forward_To "noodle" 
TAG POS=1 TYPE=B ATTR=TXT:noodle
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word9

'if find the word soup, then find the position of the image of the soup recognized by html id, id "word5", and ignore the others macros.'
SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word5

'if find the word bread, then find the position of the image of the bread recognized by html id, id "word6", and ignore the others macros.'
SET Forward_To "bread"
TAG POS=1 TYPE=B ATTR=TXT:bread
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word10

'if find the word hotdog, then find the position of the image of the hotdog recognized by html id, id "word7", and ignore the others macros.'
SET Forward_To "hotdog"
TAG POS=1 TYPE=B ATTR=TXT:hotdog
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word8

'if find the word sandwich, then find the position of the image of the sandwich recognized by html id, id "word8", and ignore the others macros.'
SET Forward_To "sandwich"
TAG TYPE=B ATTR=TXT:sandwich
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word1

'if find the word icecream, then find the position of the image of the icecream recognized by html id, id "word9", and ignore the others macros.'
SET Forward_To "icecream"
TAG POS=1 TYPE=B ATTR=TXT:icecream
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word2

'if find the word cake, then find the position of the image of the cake recognized by html id, id "word10", and ignore the others macros.'
SET Forward_To "cake" 
TAG POS=1 TYPE=B ATTR=TXT:cake
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word3

''if find the word cookie, then find the position of the image of the cookie recognized by html id, id "word11", and ignore the others macros.'
SET Forward_To "cookie" 
TAG POS=1 TYPE=B ATTR=TXT:cookie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word4

'ok here too, the final confirmation'
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:submit
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by chivracq » Mon Jan 31, 2022 3:58 pm

davinb wrote:
Sun Jan 30, 2022 4:44 pm
Hi, thanks for helping me and sorry for the delay in getting back to you, I've had an intense week.

The html is still under development, so I can only send a static example of an option.

Here is the zipped html:

https://www.dropbox.com/s/7rsvva7k4n7ji ... e.zip?dl=0

My problem is that the last command is selecting what appears on the page and not just the text item ignoring other options.

I really can't know how to do hard code, if you could give me an example by formatting the code it would help me a lot, speaking like this I can't interpret it I'm new to this all I'm trying to learn html too, just starting in this universe.

The command is to identify the text item that appears in "Customer 1 is ordering: item" and based on it, associate this item text with an id of the radio button to be clicked after validating this item text.

Sorry for my lack of knowledge and thank you very much for helping me, if you can give me a code path so that I can understand the structure I will be very grateful.

Current macro:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0 

'Select customer (ok here)'
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo-form ATTR=ID:100

'list to match the unique word that appear with one of the correct image'

'if find the word soda, then find the position of the image of the soda recognized by html id, "idword1", and ignore the others macros.'
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:10

SET Forward_To "soda"
TAG POS=1  TYPE=B ATTR=soda
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}* 
TAG POS=1 TYPE=RADIO:INPUT ATTR=ID:word6

'if find the word barbecue, then find the position of the image of the barbecue recognized by html id, id "word2", and ignore the others macros.'
SET Forward_To "barbecue" 
TAG POS=1 TYPE=B ATTR=TXT:barbecue
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word7

'if find the word pie, then find the position of the image of the pie recognized by html id, id "word3", and ignore the others macros.'
SET Forward_To "pie"
TAG POS=1 TYPE=B ATTR=TXT:pie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word11

'if find the word noodle, then find the position of the image of the noodle recognized by html id, id "word4", and ignore the others macros.'
SET Forward_To "noodle" 
TAG POS=1 TYPE=B ATTR=TXT:noodle
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word9

'if find the word soup, then find the position of the image of the soup recognized by html id, id "word5", and ignore the others macros.'
SET Forward_To "soup"
TAG POS=1 TYPE=B ATTR=TXT:soup
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word5

'if find the word bread, then find the position of the image of the bread recognized by html id, id "word6", and ignore the others macros.'
SET Forward_To "bread"
TAG POS=1 TYPE=B ATTR=TXT:bread
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word10

'if find the word hotdog, then find the position of the image of the hotdog recognized by html id, id "word7", and ignore the others macros.'
SET Forward_To "hotdog"
TAG POS=1 TYPE=B ATTR=TXT:hotdog
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word8

'if find the word sandwich, then find the position of the image of the sandwich recognized by html id, id "word8", and ignore the others macros.'
SET Forward_To "sandwich"
TAG TYPE=B ATTR=TXT:sandwich
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word1

'if find the word icecream, then find the position of the image of the icecream recognized by html id, id "word9", and ignore the others macros.'
SET Forward_To "icecream"
TAG POS=1 TYPE=B ATTR=TXT:icecream
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word2

'if find the word cake, then find the position of the image of the cake recognized by html id, id "word10", and ignore the others macros.'
SET Forward_To "cake" 
TAG POS=1 TYPE=B ATTR=TXT:cake
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word3

''if find the word cookie, then find the position of the image of the cookie recognized by html id, id "word11", and ignore the others macros.'
SET Forward_To "cookie" 
TAG POS=1 TYPE=B ATTR=TXT:cookie
TAG POS=1 TYPE=B ATTR=TXT:*{{Forward_To}}*
TAG POS=1 TYPE=INPUT:RADIO ATTR=ID:word4

'ok here too, the final confirmation'
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:submit

Alright, thanks to your Page Example, I managed to have a look at the HTML Structure, and to implement the "Workflow" I had already suggested in my previous Post... 8)

Because you only provided 1 Example, I "chose" from that Example to make the "Assumption" that "word5" would always be for "soup", "word6" for "soda", etc, and declared those 4 Mappings in an Array:

Code: Select all

SET List_Food "_word1=???_word2=???_word3=cake_word4=cookie_word5=soup_word6=soda_"
=> ... Using "_" as a Separator between 2 Entries, but could use a Comma (","), or any Char you prefer...

And that Assumption was confirmed a bit when I had a look at your Script, where you indeed hard-coded 9 Blocks of Code for 9/11 Food Items that you use, so I declared them all myself also in my Array:

Code: Select all

SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"
And instead of hard-coding 9 or 11 Blocks of Code for each Food Item, I preferred to "dynamically" retrieve the corresponding "word[1-11]" for a Food Item, which can be done with just 1 Block of Code like in:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !TIMEOUT_STEP 2
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game.html

'TAG POS=1 TYPE=P ATTR=TXT:The<SP>Food<SP>Delivery
'TAG POS=1 TYPE=H1 ATTR=TXT:Select<SP>the<SP>order<SP>to<SP>be<SP>delivered
'TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*

'Recorded: (Select "Customer [1-3]" by 'Label'.):
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>1
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:customer
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>2
'TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:customer
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>3
'TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:customer

SET Cust_Nb 1
'SET List_Food "_word1=???_word2=???_word3=cake_word4=cookie_word5=soup_word6=soda_"
SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"
TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>{{Cust_Nb}}
WAIT SECONDS=1

'Recorded: (Select "customer [1-3]" by 'RB'.):
'TAG POS=1 TYPE=IMG ATTR=SRC:file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game_files/blhpW6U.png
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:customer

'Recorded:
'TAG POS=1 TYPE=FIELDSET ATTR=TXT:Customer<SP>2<SP>Customer<SP>3<SP>Customer<SP>1<SP>is<SP>ord*
'TAG POS=1 TYPE=B ATTR=TXT:soup

'Extract "Customer [1-3] is ordering: xxx":
TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*
SET !EXTRACT NULL
TAG POS=R1 TYPE=DIV ATTR=TXT:*Customer<SP>{{Cust_Nb}}<SP>is<SP>ordering:* EXTRACT=TXT
SET Food_Item EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(':'); y=x[1]; z=y.trim(); z;")
'PROMPT Food_Item:<SP>_{{Food_Item}}_
SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")

PROMPT Food_Item:<SP>_{{Food_Item}}_<BR><BR>List_Food:<BR>_{{List_Food}}_<BR><BR>Word_ID:<SP>_{{Word_ID}}_
PAUSE

'Recorded: Click on Food Item by Image:
'TAG POS=1 TYPE=LABEL ATTR=TXT:
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid // soda
'TAG POS=2 TYPE=LABEL ATTR=TXT:
'TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:wordid // cake
'TAG POS=3 TYPE=LABEL ATTR=TXT:
'TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:wordid // cookie
'TAG POS=4 TYPE=LABEL ATTR=TXT:
'TAG POS=4 TYPE=INPUT:RADIO ATTR=NAME:wordid // soup...!!

TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid&&ID:{{Word_ID}}
WAIT SECONDS=2

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=*
(Written and tested in iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)

The Script "looks" long because I left all the Lines I recorded and all Debug-Info, but it could be shortened to...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !TIMEOUT_STEP 2
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game.html

SET Cust_Nb 1
SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"

'Select Customer [1-3] (by 'Label'):
TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>{{Cust_Nb}}
WAIT SECONDS=1

'Extract "Customer [1-3] is ordering: xxx":
TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*
SET !EXTRACT NULL
TAG POS=R1 TYPE=DIV ATTR=TXT:*Customer<SP>{{Cust_Nb}}<SP>is<SP>ordering:* EXTRACT=TXT
'>
SET Food_Item EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(':'); y=x[1]; z=y.trim(); z;")
SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")

'PROMPT Food_Item:<SP>_{{Food_Item}}_<BR><BR>List_Food:<BR>_{{List_Food}}_<BR><BR>Word_ID:<SP>_{{Word_ID}}_
'PAUSE

TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid&&ID:{{Word_ID}}
WAIT SECONDS=2

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=*
>

... And if you didn't get "it", but my little 1-Line 'EVAL()' does "the Magic" to replace your [9-11] Blocks of Code...! :idea:

Code: Select all

SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")
:shock: 8) 8) 8) 8) 8) :wink:

... Needs the "Mapping Array", and the extracted 'Food Item' of course... :wink:
And hum..., dare to shout/ask if you don't understand anything by the "x,y,z" and what they are doing... :|
- (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...
davinb
Posts: 4
Joined: Wed Jan 26, 2022 2:38 pm

Re: Help with logic to select the correct RADIO:INPUT of the puzzle based on the word as anchor of its image.

Post by davinb » Tue Feb 01, 2022 2:36 pm

chivracq wrote:
Mon Jan 31, 2022 3:58 pm
Alright, thanks to your Page Example, I managed to have a look at the HTML Structure, and to implement the "Workflow" I had already suggested in my previous Post... 8)

Because you only provided 1 Example, I "chose" from that Example to make the "Assumption" that "word5" would always be for "soup", "word6" for "soda", etc, and declared those 4 Mappings in an Array:

Code: Select all

SET List_Food "_word1=???_word2=???_word3=cake_word4=cookie_word5=soup_word6=soda_"
=> ... Using "_" as a Separator between 2 Entries, but could use a Comma (","), or any Char you prefer...

And that Assumption was confirmed a bit when I had a look at your Script, where you indeed hard-coded 9 Blocks of Code for 9/11 Food Items that you use, so I declared them all myself also in my Array:

Code: Select all

SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"
And instead of hard-coding 9 or 11 Blocks of Code for each Food Item, I preferred to "dynamically" retrieve the corresponding "word[1-11]" for a Food Item, which can be done with just 1 Block of Code like in:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !TIMEOUT_STEP 2
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game.html

'TAG POS=1 TYPE=P ATTR=TXT:The<SP>Food<SP>Delivery
'TAG POS=1 TYPE=H1 ATTR=TXT:Select<SP>the<SP>order<SP>to<SP>be<SP>delivered
'TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*

'Recorded: (Select "Customer [1-3]" by 'Label'.):
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>1
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:customer
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>2
'TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:customer
'TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>3
'TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:customer

SET Cust_Nb 1
'SET List_Food "_word1=???_word2=???_word3=cake_word4=cookie_word5=soup_word6=soda_"
SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"
TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>{{Cust_Nb}}
WAIT SECONDS=1

'Recorded: (Select "customer [1-3]" by 'RB'.):
'TAG POS=1 TYPE=IMG ATTR=SRC:file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game_files/blhpW6U.png
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:customer

'Recorded:
'TAG POS=1 TYPE=FIELDSET ATTR=TXT:Customer<SP>2<SP>Customer<SP>3<SP>Customer<SP>1<SP>is<SP>ord*
'TAG POS=1 TYPE=B ATTR=TXT:soup

'Extract "Customer [1-3] is ordering: xxx":
TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*
SET !EXTRACT NULL
TAG POS=R1 TYPE=DIV ATTR=TXT:*Customer<SP>{{Cust_Nb}}<SP>is<SP>ordering:* EXTRACT=TXT
SET Food_Item EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(':'); y=x[1]; z=y.trim(); z;")
'PROMPT Food_Item:<SP>_{{Food_Item}}_
SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")

PROMPT Food_Item:<SP>_{{Food_Item}}_<BR><BR>List_Food:<BR>_{{List_Food}}_<BR><BR>Word_ID:<SP>_{{Word_ID}}_
PAUSE

'Recorded: Click on Food Item by Image:
'TAG POS=1 TYPE=LABEL ATTR=TXT:
'TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid // soda
'TAG POS=2 TYPE=LABEL ATTR=TXT:
'TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:wordid // cake
'TAG POS=3 TYPE=LABEL ATTR=TXT:
'TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:wordid // cookie
'TAG POS=4 TYPE=LABEL ATTR=TXT:
'TAG POS=4 TYPE=INPUT:RADIO ATTR=NAME:wordid // soup...!!

TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid&&ID:{{Word_ID}}
WAIT SECONDS=2

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=*
(Written and tested in iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)

The Script "looks" long because I left all the Lines I recorded and all Debug-Info, but it could be shortened to...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !TIMEOUT_STEP 2
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=file:///D:/TEMP/iMacros/Temp/_Forum%20Cases/davinb/thefoodgame/The%20Food%20Game.html

SET Cust_Nb 1
SET List_Food "_word1=sandwich_word2=icecream_word3=cake_word4=cookie_word5=soup_word6=soda_word7=barbecue_word8=hotdog_word9=noodle_word10=bread_word11=pie_"

'Select Customer [1-3] (by 'Label'):
TAG POS=1 TYPE=LABEL ATTR=TXT:Customer<SP>{{Cust_Nb}}
WAIT SECONDS=1

'Extract "Customer [1-3] is ordering: xxx":
TAG POS=1 TYPE=P ATTR=TXT:Select<SP>the<SP>customer<SP>and<SP>then<SP>match<SP>the*
SET !EXTRACT NULL
TAG POS=R1 TYPE=DIV ATTR=TXT:*Customer<SP>{{Cust_Nb}}<SP>is<SP>ordering:* EXTRACT=TXT
'>
SET Food_Item EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(':'); y=x[1]; z=y.trim(); z;")
SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")

'PROMPT Food_Item:<SP>_{{Food_Item}}_<BR><BR>List_Food:<BR>_{{List_Food}}_<BR><BR>Word_ID:<SP>_{{Word_ID}}_
'PAUSE

TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:wordid&&ID:{{Word_ID}}
WAIT SECONDS=2

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=*
>

... And if you didn't get "it", but my little 1-Line 'EVAL()' does "the Magic" to replace your [9-11] Blocks of Code...! :idea:

Code: Select all

SET Word_ID EVAL("var list='{{List_Food}}', fi='{{Food_Item}}'; var x,y,z; x=list.split(fi); y=x[0].split('_'); z=y[y.length-1].split('=')[0]; z;")
:shock: 8) 8) 8) 8) 8) :wink:

... Needs the "Mapping Array", and the extracted 'Food Item' of course... :wink:
And hum..., dare to shout/ask if you don't understand anything by the "x,y,z" and what they are doing... :|
Chivracq, you are wonderful. Thank you so much for taking the time to help us on this forum. The code worked perfectly, I could understand very well now how to make a hard-code and I thought it was really cool. :D

However, as you can already deduce, I had difficulties interpreting the language of the variables :oops: , I just didn't understand the meaning of the lines of the variables, even though you explained what each line would be for. I confess that I'm scared and seeming to come across complex math functions (which I'm not good at haha) :shock:, if you could explain to me what each part means I would be very happy to learn and understand how to produce this logic in variables and if can you also send me links or sources that teach about the variables you set up will be amazing :P.

I tried to reproduce this variable logic but as I don't know the way I faced this error and I don't know how to solve it. Could you explain in detail how you could use it in general so that I can understand the logic? :?

10:23:40: Error: "-1250: JScriptError" at line 36
SET Food_Item EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(':'); y=x[1]; z=y.trim(); z;")
Cannot read property 'trim' of undefined :shock:
Post Reply