[Solved]Enable checkbox if unchecked

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
Adam86
Posts: 3
Joined: Tue Feb 14, 2017 11:11 am

[Solved]Enable checkbox if unchecked

Post by Adam86 » Tue Feb 14, 2017 11:20 am

Good morning,

Really pulling my hair out with this one. Maybe my old age is starting to kick in but I just can't seem to figure it out.

I have a website that has a checkbox to enable/disable something.

What I want to do is setup an iMacros script that will load up the page on the site which I can do no problem, and then check if the checkbox is ticked or not.

If the checkbox is unticked then I want it to enable it, if it is unchecked then I just want the script to end and not do anything.

This is what I've made so far:

Code: Select all

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://url.com/etc
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:login-hidden ATTR=ID:email CONTENT=xxx@domain.com
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:login-hidden ATTR=ID:password CONTENT=password
WAIT SECONDS=5
TAG POS=15 TYPE=DIV ATTR=TXT:
TAG POS=16 TYPE=DIV ATTR=CLASS:icon&&TXT:
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 EXTRACT=CHECKED
Now I have no idea what to do - I know that the following toggles the checkbox:

TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 CONTENT=YES

So therefore if the checkbox is already ticked it appears to uncheck it, hence why I need to put this check in place because I just want it to check if already unchecked.

This is using iMacros for Firefox 8.97 with Firefox 47.

Thanks
Last edited by Adam86 on Tue Feb 14, 2017 8:21 pm, edited 1 time in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Enable checkbox if unchecked

Post by chivracq » Tue Feb 14, 2017 3:05 pm

Adam86 wrote:This is using

Code: Select all

iMacros for Firefox 8.97 with Firefox 47.
Good morning,

Really pulling my hair out with this one. Maybe my old age is starting to kick in but I just can't seem to figure it out.

I have a website that has a checkbox to enable/disable something.

What I want to do is setup an iMacros script that will load up the page on the site which I can do no problem, and then check if the checkbox is ticked or not.

If the checkbox is unticked then I want it to enable it, if it is unchecked then I just want the script to end and not do anything.

This is what I've made so far:

Code: Select all

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://url.com/etc
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:login-hidden ATTR=ID:email CONTENT=xxx@domain.com
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:login-hidden ATTR=ID:password CONTENT=password
WAIT SECONDS=5
TAG POS=15 TYPE=DIV ATTR=TXT:
TAG POS=16 TYPE=DIV ATTR=CLASS:icon&&TXT:
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 EXTRACT=CHECKED
Now I have no idea what to do - I know that the following toggles the checkbox:

Code: Select all

TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 CONTENT=YES
So therefore if the checkbox is already ticked it appears to uncheck it, hence why I need to put this check in place because I just want it to check if already unchecked.

Thanks
OS is missing from your FCI even if it won't play a role in this case, but your Post is perfect... :D

Hum, "If the checkbox is unticked then..., if it is unchecked then..." both sound like the same to me... :?

But OK, you are very close and you've managed to find the "EXTRACT=CHECKED", very good...!, which indeed returns "YES" or "NO", and not "TRUE"/"FALSE" like mentioned in the Wiki I think, then you simply use 'EVAL()' to spit out a "1"/"0" to reuse on the 'POS=1' for ticking your Checkbox ('TAG POS=0' won't do anything), with !ERRORIGNORE' enabled...:

Code: Select all

'...
TAG POS=15 TYPE=DIV ATTR=TXT:
TAG POS=16 TYPE=DIV ATTR=CLASS:icon&&TXT:

'Check Checkbox only if Not Checked already:
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 EXTRACT=CHECKED
SET Check_CB EVAL("var s='{{!EXTRACT}}'; var z; if(s=='YES'){z=0;} else{z=1;}; z;")
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
TAG POS={{Check_CB}} TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 CONTENT=YES
PROMPT CB<SP>checked...?:<SP>_{{[!EXTRACT}}_<BR>Check_CB:<SP>_{{Check_CB}}_
Not tested, I've added some 'PROMPT' Statement for you to debug your Script, you'll need the "YES" in the 'EVAL()' Statement to match what gets returned by the 'EXTRACT' => YES/NO like I think, or maybe TRUE/FALSE...

EDIT: Typo corrected about "PROMP" => "PROMPT" in the last Line of my Script... :oops:
Last edited by chivracq on Thu Jul 26, 2018 6:15 am, edited 1 time in total.
- (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...
Adam86
Posts: 3
Joined: Tue Feb 14, 2017 11:11 am

Re: Enable checkbox if unchecked

Post by Adam86 » Tue Feb 14, 2017 3:36 pm

OS is missing from your FCI even if it won't play a role in this case, but your Post is perfect... :D

Hum, "If the checkbox is unticked then..., if it is unchecked then..." both sound like the same to me... :?

But OK, you are very close and you've managed to find the "EXTRACT=CHECKED", very good...!, which indeed returns "YES" or "NO", and not "TRUE"/"FALSE" like mentioned in the Wiki I think, then you simply use 'EVAL()' to spit out a "1"/"0" to reuse on the 'POS=1' for ticking your Checkbox ('TAG POS=0' won't do anything), with !ERRORIGNORE' enabled...:

Code: Select all

'...
TAG POS=15 TYPE=DIV ATTR=TXT:
TAG POS=16 TYPE=DIV ATTR=CLASS:icon&&TXT:

'Check Checkbox only if Not Checked already:
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 EXTRACT=CHECKED
SET Check_CB EVAL("var s='{{!EXTRACT}}'; var z; if(s=='YES'){z=0;} else{z=1;}; z;")
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
TAG POS={{Check_CB}} TYPE=INPUT:CHECKBOX ATTR=ID:settings_switch_0 CONTENT=YES
PROMP CB<SP>checked...?:<SP>_{{[!EXTRACT}}_<BR>Check_CB:<SP>_{{Check_CB}}_
Not tested, I've added some 'PROMPT' Statement for you to debug your Script, you'll need the "YES" in the 'EVAL()' Statement to match what gets returned by the 'EXTRACT' => YES/NO like I think, or maybe TRUE/FALSE...
Oh darn it :-( thats what you get for typing a message too quickly and not checking it over.

I was meant to say if the checkbox is unticked then I want to toggle it to enabled and if it is already enabled then I don't need anything else and the script can just close the browser.

Does that change the code at all now I have worded myself correct - terribly sorry feel very silly now!

Thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Enable checkbox if unchecked

Post by chivracq » Tue Feb 14, 2017 4:46 pm

Adam86 wrote:Oh darn it :-( thats what you get for typing a message too quickly and not checking it over.

I was meant to say if the checkbox is unticked then I want to toggle it to enabled and if it is already enabled then I don't need anything else and the script can just close the browser.

Does that change the code at all now I have worded myself correct - terribly sorry feel very silly now!

Thanks
Yeah-yeah, don't worry, that's what I had understood as well..., and that's what "my" Macro is supposed to do, check if the CB is already checked and if not, will check it, otherwise do nothing with that CB and continue processing the rest of your Macro if you have any Code after that part...
- (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...
Adam86
Posts: 3
Joined: Tue Feb 14, 2017 11:11 am

Re: Enable checkbox if unchecked

Post by Adam86 » Tue Feb 14, 2017 5:00 pm

Absolutely fantastic, just tested the script and it does exactly what I want it to do! it appears to work just as you'd expect in both circumstances.

Been pulling my hair out with this one for days, I can't thank you enough for assisting with this.

Thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Enable checkbox if unchecked

Post by chivracq » Tue Feb 14, 2017 5:30 pm

Adam86 wrote:Absolutely fantastic, just tested the script and it does exactly what I want it to do! it appears to work just as you'd expect in both circumstances.

Been pulling my hair out with this one for days, I can't thank you enough for assisting with this.

Thanks
Ah-ah...!, glad I could help and you were very close with the 'EXTRACT=CHECKED', and I guess you could have found the Answer on the Forum as well as I've already answered this Qt a few times..., maybe not with complete Script as I guess most Users before you were too "lazy" to read any Documentation or try anything or even search the Forum before asking directly on the Forum...

Could be handy for other Users searching the Forum with the same Qt if you could add a "[Solved]" or "[SOLVED]" Tag to your Thread Title (Original Post in this Thread) for them to locate this Thread more easily... :idea:

EDIT: "[Solved]" added to Thread Title, perfect...! 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...
Post Reply