Number of Options in a Select tag

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
rfashanu2
Posts: 1
Joined: Sun Apr 06, 2008 2:54 pm

Number of Options in a Select tag

Post by rfashanu2 » Sun Apr 06, 2008 2:59 pm

Hello.. I need to find out how I can get the number of options in a Select tag

For example, the following Select tag has 3 options. I would like to be able to get the value 3 using Imacros and some VBScripting if required..

Code: Select all

	<SELECT NAME="name1">
		<OPTION VALUE="value1" SELECTED>Item1
		<OPTION VALUE="value2" >Item2 
		<OPTION VALUE="value3" >Item3 
	</SELECT>
thanks
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: Number of Options in a Select tag

Post by Tech Support » Sun Apr 06, 2008 11:41 pm

Here is how to get the number of entries in a select box:

1. Use a TAG command that tries to select a non-existing entry. Example:

Code: Select all

URL GOTO=http://www.iopus.com/imacros/demo/v6/f1/form.asp     
TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:main CONTENT=2000 
2. The returned error message contains the number of entries in the select box:
Selected entry not available:2000 [Box has 3 entries]. Disable this message with SET !ERRORIGNORE YES

This error message is also returned via iimGetLastError, so you can use this value with VBS and any other programming language.
chivracq
Posts: 8636
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Number of Options in a Select tag

Post by chivracq » Fri Aug 28, 2015 1:17 am

I needed the same Functionality in pure .iim as I don't use any .js Scripts (in order to be able to select automatically the last possible Option in a DDLB with a variable Number of Options...) and I came up with the following Solution:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1
'SET !EXTRACT_TEST_POPUP NO

URL GOTO=http://www.iopus.com/imacros/demo/v6/f1/form.asp
'TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main CONTENT=$French<SP>Fries

TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main EXTRACT=TXTALL
'=> Extracted: "--- Please select ---[OPTION]Pizza[OPTION]French Fries[OPTION]Bread & Butter"

'Calculate Nb of Options in DDLB (by using the Length of the Array after a 'split()'):
SET DDLB_Nb_of_Options EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('[OPTION]'); x=y.length; x;")
PROMPT DDLB_Nb_of_Options:<SP>_{{DDLB_Nb_of_Options}}_

'Select Last Option in DDLB:
TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main CONTENT=#{{DDLB_Nb_of_Options}}
'=> 'Bread & Butter' gets selected!
(Tested on iMacros for FF v8.8.2, Pale Moon v24.6.2 (=FF31), Win7-x64.)

>>>

EDIT (Tu.2015/10/27):
Adding a few TAGS to be able to find this Thread again as the 'SEARCH FORUM' Functionality doesn't look into 'CODE' Blocks:
JFC_TAG/JFC_TAGS: DDLB, Array, Length, SELECT, Option, Options, EVAL, split
- (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...
chivracq
Posts: 8636
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Number of Options in a Select tag

Post by chivracq » Thu May 12, 2016 3:38 pm

Ah-ah-ah...!! Mini-Explanation for myself (yep, I'm a bit dumb sometimes...!) about the Code in my previous Post as I was just reviewing it to refer to this Thread for some other Thread, I thought for a while there was a mini-Mistake in my use of the Length of the Array as I would expect a -1 to get the correct Number of Items, but...!, Explanation is that it is a DDLB with a first empty Row before selecting any Item in the DDLB...

And I'm not sure my Remark about the Forum Search Engine not being able to search inside ']code[' Blocks is correct...
OK, testing now:

Code: Select all

UniKKeyWWord Ah-ah...!
Yep, doesn't work (using the exact same Spelling, with Capitals included):
No posts were found because the word unikkeywword is not contained in any post.

Code: Select all

unikkeywword Ah-ah...!
Well, doesn't work either (using lowercase for the Search Term and having truncated the previous Quote), but the Msg is different:
No suitable matches were found.
And if I don't truncate the "Keyword" in the first Quote, the Post is found (same Result using Lowercase or with Capitals included) with all Words highlighted...!? :?

It's a bit confusing, but it seems I was right, the Forum Search Engine does NOT look inside ']code[' Blocks, or it looks inside for the Highlighting but only if the Term has already been found in Plain Text or in a Quote within the same Post.
- (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