Running conditional code

Discussions and Tech Support related to the iMacros Google Chrome extension.
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
sinan73
Posts: 3
Joined: Sun Feb 17, 2019 12:41 pm

Running conditional code

Post by sinan73 » Tue Feb 19, 2019 11:42 am

Hello there,

iMacros Version: 1005 Recorder = CR
OS: Windows 7 (x64)
Browser: Chrome 72.0.3626.109 (x64)

What I want to do is;

If the search for the following code succeeds

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
Let the code work,

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
If it doesn't, don't run the code.

Sorry about my bad english.
iMacros Version:1005 Recorder=CR (Free)
OS: Windows 7 (x64)
Browser: Chrome 72.0.3626.109 (x64)
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Running conditional code

Post by chivracq » Tue Feb 19, 2019 6:14 pm

sinan73 wrote:
Tue Feb 19, 2019 11:42 am
Hello there,
iMacros Version: 1005 Recorder = CR
OS: Windows 7 (x64)
Browser: Chrome 72.0.3626.109 (x64)
What I want to do is;

If the search for the following code succeeds

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
Let the code work,

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
If it doesn't, don't run the code.

Sorry about my bad english.
FCI mentioned, perfect...! ('Free'/'PE' is missing though...)

Yep, fairly "basic" Functionality that you want, and you have several Options:
1- Use the 'SEARCH' Command.
OK, that Command is "meant" for what you want, but I never use it myself as I find it a bit "not very easy" to use, and there are "easier" ways in my Opinion...

2- Tag and extract your Element to check if it is present or not using 'EVAL()' to spit out a "1"/"0" to reuse on 'TAG POS=n' ('TAG POS={{!VAR1}}') for your second Element, 'TAG POS=0' won't do anything when you don't want to click on that Element.

3- And probably even (muuuuuch) easier, simply use 'Relative Positioning' in this Case... :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...
sinan73
Posts: 3
Joined: Sun Feb 17, 2019 12:41 pm

Re: Running conditional code

Post by sinan73 » Tue Feb 19, 2019 7:21 pm

Thank you for answering. I'm using the free version.

The 'Relative Positioning' and the 'SEARCH' command are too complicated for what I want.

I did a lot of research on EVAL, but I don't know how to write the code you specified in option 2, can you help me?
iMacros Version:1005 Recorder=CR (Free)
OS: Windows 7 (x64)
Browser: Chrome 72.0.3626.109 (x64)
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Running conditional code

Post by chivracq » Tue Feb 19, 2019 7:49 pm

sinan73 wrote:
Tue Feb 19, 2019 7:21 pm
Thank you for answering. I'm using the free version.

The 'Relative Positioning' and the 'SEARCH' command are too complicated for what I want.

I did a lot of research on EVAL, but I don't know how to write the code you specified in option 2, can you help me?
Ah, OK for 'Free Version'...

Hum, and I forgot to mention, try to select the "correct" Sub-Forum (next time) when you open a Thread, your Thread has nothing specific to 'iMacros for CR' (only) and should have been opened in the 'General' Sub-Forum, or the 'Data Extraction' Sub-Forum would also have been "correct"... But OK, good enough for this time..., and no need to duplicate of course...

Yeah well, the 'Relative Positioning' way is from very faaaaar, the easiest...! You simply need to add an "R" to your existing Code, ah-ah...!! There is nothing "complicated" about that, ah-ah...! (Or you can already completely forget about iMacros, oops...!) :shock: :

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-cross
The 'TAG POS=R1' won't do anything if the first 'TAG' is not found... 8)

Hum, OK, and you need to activate '!ERRORIGNORE' of course for when your "Search Element" = 'Anchor' is not present..., or if the 2nd Element also might not always be present, unless you prefer to let your Script automatically abort..., and you'll probably want to shorten '!TIMEOUT_STEP' to "1" or "0":

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-cross
See how simple it is...!? :wink:
- (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...
sinan73
Posts: 3
Joined: Sun Feb 17, 2019 12:41 pm

Re: Running conditional code

Post by sinan73 » Tue Feb 19, 2019 8:47 pm

Sorry, but it didn't work.

This code works:

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
But this code doesn't work:

Code: Select all

TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-cross
All the codes in the macro:

Code: Select all

VERSION BUILD=1005 RECORDER=CR
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1
TAB T=1
FRAME F=3
TAG POS=1 TYPE=P ATTR=CLASS:time-left-author&&DATA-ABJSON:your_time_left
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=TXT:Yeni<SP>oyun 
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:lose-category-radios
TAG POS=1 TYPE=BUTTON ATTR=TXT:Oyna
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:lose-category-radios
TAG POS=1 TYPE=BUTTON ATTR=TXT:Oyna
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=BUTTON ATTR=TXT:Devam<SP>Et
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=BUTTON ATTR=TXT:Kabul<SP>Et 
WAIT SECONDS=1
TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-back<SP>icon-arrow-back 'If the code above works (if TAG is found) I would like to run this code.
WAIT SECONDS=3
iMacros Version:1005 Recorder=CR (Free)
OS: Windows 7 (x64)
Browser: Chrome 72.0.3626.109 (x64)
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Running conditional code

Post by chivracq » Tue Feb 19, 2019 9:22 pm

sinan73 wrote:
Tue Feb 19, 2019 8:47 pm
Sorry, but it didn't work.

This code works:

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Kabul<SP>Et
But this code doesn't work:

Code: Select all

TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-cross
All the codes in the macro:

Code: Select all

VERSION BUILD=1005 RECORDER=CR
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1
TAB T=1
FRAME F=3
TAG POS=1 TYPE=P ATTR=CLASS:time-left-author&&DATA-ABJSON:your_time_left
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=TXT:Yeni<SP>oyun 
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:lose-category-radios
TAG POS=1 TYPE=BUTTON ATTR=TXT:Oyna
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:RADIO ATTR=NAME:lose-category-radios
TAG POS=1 TYPE=BUTTON ATTR=TXT:Oyna
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=BUTTON ATTR=TXT:Devam<SP>Et
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
TAG POS=1 TYPE=SPAN ATTR=CLASS:icon-cross
WAIT SECONDS=1
TAG POS=1 TYPE=BUTTON ATTR=TXT:Kabul<SP>Et 
WAIT SECONDS=1
TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-back<SP>icon-arrow-back 'If the code above works (if TAG is found) I would like to run this code.
WAIT SECONDS=3
=> OK, about this part:

Code: Select all

TAG POS=1 TYPE=BUTTON ATTR=TXT:Kabul<SP>Et 
WAIT SECONDS=1
TAG POS=R1 TYPE=SPAN ATTR=CLASS:icon-back<SP>icon-arrow-back 'If the code above works (if TAG is found) I would like to run this code.
WAIT SECONDS=3
Well, your original "Kabul Et" Element was a 'SPAN' Element, but now it's a 'BUTTON'... :?
If that Button is triggering a Page Reload (or some new Page), then yep, the 'TAG POS=R1' won't work as both the 'Anchor' and the 'R-TAG' Element need to be on the same Page, I think...

No URL provided and your Site is probably behind L&P, then I can't have a look...
=> Can always go back to Option '2-' with 'EXTRACT' + 'EVAL()', then... I must have posted that Method more than 100 times already, if you search the Forum a bit... :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...
Post Reply