[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.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

[Solved]Enable checkbox if unchecked

by Adam86 on Tue Feb 14, 2017 4: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 1:21 pm, edited 1 time in total.
Adam86
 
Posts: 3
Joined: Tue Feb 14, 2017 4:11 am

Re: Enable checkbox if unchecked

by chivracq on Tue Feb 14, 2017 8:05 am

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
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...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6484
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Enable checkbox if unchecked

by Adam86 on Tue Feb 14, 2017 8:36 am

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

Re: Enable checkbox if unchecked

by chivracq on Tue Feb 14, 2017 9:46 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6484
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Enable checkbox if unchecked

by Adam86 on Tue Feb 14, 2017 10:00 am

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

Re: Enable checkbox if unchecked

by chivracq on Tue Feb 14, 2017 10:30 am

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:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6484
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 9 guests

-->