FAIL_IF_FOUND on Checkbox value

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

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.

FAIL_IF_FOUND on Checkbox value

by seanouk on Sun May 29, 2016 3:57 pm

Hi there..

I am VERY new to iMacros, and am so far very impressed.
As I am only trialling the product at present I am using the free version. (v11)

I am using the product to create automated regression testing, and so checking results is a key element of my macros.

I am currently trying to run a macro which proves whether or not a check box on a page has been ticked.

If the checkbox is not ticked (or is ticked, whichever) I want the Macro to error (FAIL_IF_FOUND?)

I am not sure the best way to accomplish this. I had it working using image search, but the free version does not include this feature.

How do I extract the value of a checkbox, and then fail the Macro if the value is either YES or NO?

Windows 8.1, IE11
iMacros Sidebar for Internet Explorer (x64) Version 11.1.495.5175
Released on 10/03/2016
Licensed Product: Free Edition

Many thanks in advance.
seanouk
 
Posts: 2
Joined: Sun May 29, 2016 3:50 pm

Re: FAIL_IF_FOUND on Checkbox value

by chivracq on Sun May 29, 2016 5:18 pm

seanouk wrote:Hi there..

I am VERY new to iMacros, and am so far very impressed.
As I am only trialling the product at present I am using the free version. (v11)

I am using the product to create automated regression testing, and so checking results is a key element of my macros.

I am currently trying to run a macro which proves whether or not a check box on a page has been ticked.

If the checkbox is not ticked (or is ticked, whichever) I want the Macro to error (FAIL_IF_FOUND?)

I am not sure the best way to accomplish this. I had it working using image search, but the free version does not include this feature.

How do I extract the value of a checkbox, and then fail the Macro if the value is either YES or NO?

Code: Select all
Windows 8.1, IE11
iMacros Sidebar for Internet Explorer (x64) Version 11.1.495.5175
Released on 10/03/2016
Licensed Product: Free Edition


Many thanks in advance.

You could indeed use 'FAIL_IF_FOUND' to stop your Macro but it's a bit cumbersome... The "normal" way to achieve what you want is first to use 'EXTRACT=CHECKED' when tagging your Checkbox, which will return "true"/"false", and using 'EVAL()' to trigger a 'MacroError()'.

Hum..., mistake in the Wiki, it doesn't return "true"/"false" but "YES"/"NO"...!
Working Example:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
'URL GOTO=http://forum.imacros.net/posting.php?mode=quote&f=7&p=69423

'TAG POS=1 TYPE=LABEL FORM=ID:postform ATTR=TXT:Attach<SP>a<SP>signature<SP>(signatures<SP>can<SP>be<SP>alte*
'TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:postform ATTR=ID:attach_sig CONTENT=NO
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:postform ATTR=ID:attach_sig EXTRACT=CHECKED
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s=='YES'){MacroError('Checkbox is CHECKED...!');}")
PROMPT {{!EXTRACT}}
(Tested on iMacros for FF v8.8.2, Pale Moon v26.1.1 (=FF43), Win10-x64.)
- (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: 6474
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: FAIL_IF_FOUND on Checkbox value

by seanouk on Mon May 30, 2016 3:06 pm

Thank you so much! Got that working now.

Just so I understand though, can you clarify please how I can allow the Macro to continue running, but to log this error in the output log?

Many thanks
seanouk
 
Posts: 2
Joined: Sun May 29, 2016 3:50 pm

Re: FAIL_IF_FOUND on Checkbox value

by chivracq on Mon May 30, 2016 5:58 pm

seanouk wrote:Thank you so much! Got that working now.

Just so I understand though, can you clarify please how I can allow the Macro to continue running, but to log this error in the output log?

Many thanks

To continue running anyway, you mean...? Well, same Principle, you do what you want with the String you produce for the Error Msg...
If I reuse my previous Script, that would give stg like:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
'SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=http://forum.imacros.net/posting.php?mode=quote&f=7&p=69423

'Define a few Vars for "easy" Access:
'Define Stopping/Logging Condition (Checked/Not Checked: "YES"/"NO")
SET SL_Cond YES
'>
'Define Error Msg:
SET Error_Msg "Checkbox is CHECKED...!"

'Extract if Checkbox is Checked or not:
'TAG POS=1 TYPE=LABEL FORM=ID:postform ATTR=TXT:Attach<SP>a<SP>signature<SP>(signatures<SP>can<SP>be<SP>alte*
'TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:postform ATTR=ID:attach_sig CONTENT=NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:postform ATTR=ID:attach_sig EXTRACT=CHECKED
SET CB_Status {{!EXTRACT}}

'Log "Error" to 'output.csv' File if Condition is met:
SET Log_Msg EVAL("var s='{{CB_Status}}'; var c='{{SL_Cond}}', var err='{{Error_Msg}}'; var x; if(s==c){x=err;} else{x='';}}; x;")
SET !EXTRACT {{Log_Msg}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE="output.csv"

'Stop Macro if Condition is met. (Comment out if you don't want to stop the Macro...!):
SET !ERRORIGNORE NO
'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s=='YES'){MacroError('Checkbox is CHECKED...!');}")
SET !VAR1 EVAL("var s='{{CB_Status}}'; var c='{{SL_Cond}}', if(s==c){MacroError(\"{{Error_Msg}}\");}")
'SET !ERRORIGNORE YES

'Define Msg for PROMPT to show that Macro didn't stop:
SET PROMPT_Msg "Macro is still running...!"
ADD PROMPT_Msg <BR>EXTRACT:<SP>{{CB_Status}}<SP>(Checkbox<SP>not<SP>checked...!)
PROMPT {{PROMPT_Msg}}
(Tested on iMacros for FF v8.8.2, Pale Moon v26.1.1 (=FF43), Win10-x64.)
- (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: 6474
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 4 guests

-->