I am looking to automate selecting an item from a list where the generated HTML looks like:
<select name="uid_1"">
<option value="0">All</option>
<option value="1">Option A</option>
<option value="2">Option B</option>
<option value="3">Option C</option>
</select>
I can use the iMacros script line to select Option A, which has a value of 1:
TAG POS=1 TYPE=SELECT FORM=NAME:myForm ATTR=NAME:uid_1 CONTENT=%1
But I need to select by the display text "Option A" as this will be more stable than the options value.
Is this possible with iMacros?
Note that I am using the iMacros plug in for Firefox.
Better answer: Use a $ instead of a %.
TAG POS=1 TYPE=SELECT FORM=NAME:myForm ATTR=NAME:uid_1 CONTENT=$Option<SP>A
Note: The <SP> command indicates a space and is case sensitive.
Related
I want to create a regex which gives result for the selected field in a drop down list for a particular id.
For example: if I pass id="countries" the result should be India (since India is selected) or id="Gender" the result should be Male.
<select id='countries'>
<optionvalue='0'>All Categories</option>
<option value='1'>USA</option>
<option value='2'>China</option>
<option selected='selected' value='3'>India</option>
<option value='4'>Japan</option>
</select>
<select id='Gender'>
<option value='0'>All Categories</option>
<option selected='selected' value='1'>Male</option>
<option value='2'>Female</option>
</select>
Note: Consider above HTML as a plane text.
Extracting HTML data using regex is a very very very bad idea. It's complicated and inefficient. You are better off using a HTML parser (such as JSoup or BeautifulSoup) for HTML, a JSON library for parsing JSON, etc.
That being said, here is a regex that should work as long as the id is quoted. If your id is in a variable called id, then your regex will be
regex = "<select[^>]*? id=['\"]" + id
+ "['\"].*?<option[^>]*? selected[^>]*?>([^<]*)";
Note that for this to work, the select with that id must actually have a selected option.
I want to select the nth option (for example, the second), regardless of which the value is.
TAG TYPE=SELECT ... CONTENT=(the second option)
How may I approach this?
Read the related wiki page and you can find this way:
TAG POS=1 TYPE=SELECT ... CONTENT=#2
have a small Problem to choose a value ID in special Dropdown Box with iMacros. The Dropdown is on mrssporty.de/. It's the first Box in the main Fomular for Selecting the Club.
I have the the Value Ids like this:
<select id="clubUid" name="form66[clubUid]" class="form-control select select2 select2init">
<option value="">PLZ oder Ort eingeben *</option>
<option value="1139" >Aalen (73430, Bahnhofstraße 8)</option>
<option value="26" >Ahrensburg (22926, Grosse Strasse 2)</option>
<option value="27" >Aichach (86551, Augsburgerstr. 17)</option>
<option value="1128" >Altötting (84503, Marienstr.3)</option>
<option value="29" >Alzey (55232, Berliner Strasse 3)</option>
and want to choose one value above with iMacros like
TAG POS=1 TYPE=SELECT FORM=* ATTR=ID:select2-drop CONTENT=$1139
Use these settings in Recording Options.
http://i.imgur.com/pLeKEHa.png
And record selection of drop down.
If you have multiple dropdowns and u want to do them all you can record 2 or 3. Then you can see which number inside () is changing. Then place !LOOP inside that number.
(!LOOP)
With little work u will see what I mean.
actually i solved it like that
EVENT TYPE=MOUSEDOWN SELECTOR="#select2-chosen-3" BUTTON=0
CLICK X=646 Y=267
wait seconds=1
EVENTS TYPE=KEYPRESS SELECTOR="#s2id_autogen3_search" CHARS="12587"
EVENTS TYPE=KEYPRESS SELECTOR="#s2id_autogen3_search" KEYS="[13,13]"
But its not really smart. Anyone a better Idea?
I'm new to imacros and am having a little trouble figuring out this script. Here is my imacros script
VERSION BUILD=8920312 RECORDER=FX
TAB T=1
SET !DATASOURCE input.csv
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://URL.com/Property/Search
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/Property/Search ATTR=ID:PropertyAddress CONTENT={{!COL1}}
TAG POS=1 TYPE=BUTTON FORM=ACTION:/Property/Search ATTR=ID:btnSearchSubmit
WAIT SECONDS=10
TAG POS=1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\admin\Documents\iMacros\Downloads FILE=extract.csv`
The input.csv has a list of addresses. That part works fine.
The part I'm having trouble with is extracting text. Here is the code from the page with the text I want to extract:
<td colspan="5" class="style2">
TEXT TO EXTRACT
</td>
I have the extract.csv in the downloads folder so I don't think that's an issue. The script seems to run fine except for it's not extracting the text. The text extraction popup is just blank.
I'm also having trouble determining the best way to save the extracted the data. All of the data in the input.csv is addresses and they're all in column 1. Some of them will not return any results when submitted.
Ideally, when saving the extracted data I'd like to save both the address pulled from the {{!COL1}} variable and the extracted data to the same row in the extract.csv spread sheet with the address and extracted data being in separate columns.
Hope I explained that well enough. Thanks in advance for any pointers!
The second part of your question can be solved simply by adding one line after WAIT SECONDS=10 :
SET !EXTRACT {{!COL1}} .
The issue as to extraction seems to lie in a wrong TYPE=TD (or just in absence of any text, if ‘iMacros’ doesn’t return the ‘#EANF#’ value). Try to record again a click on the element you want to extract text from and compare the obtained command with your TAG POS=1 TYPE=TD ATTR=TXT:* EXTRACT=TXT .
Anyway you might test for example:
TAG POS=1 TYPE=TD ATTR=COLSPAN:5&&CLASS:style2 EXTRACT=TXT .
Consider the following text that might be part of an HTTP response from jMeter:
<menu id="Alpha" name="alpha">
<option value="a">A</option>
<option value="b">B</option>
<option value="c" selected="selected">C</option>
</menu>
<menu id="Bravo" name="bravo">
<option value="d">D</option>
<option value="e">E</option>
</menu>
I'm trying to extract the ID of each menu, as well as the selected option's value if there is an option selected. If there is no option selected, then by default, the first option's value should be matched. For example, in this example, I want the following to be matched:
"Alpha" "c"
"Bravo" "d"
So far, I have written the following:
<select id="Form:parameterList:([^"]+?)".*?>.*?(?:<option value="([^"]*?)".*?(?:selected="selected")?>)?.*?</select>
The problem with this is that only the first option's value is ever matched, and the selected option is never matched. That is, I want to prioritize matching the optional pattern.
Thanks,
Victor
Consider how maintainable your script will be using that complex regex.
You can achieve the result you desire using xpath extractors, conditional/loop controllers and or post-processors...
First get a list of all ids:
//menu/#id
You can get a list of ids containing an option with attribute selected = 'selected' with something similar to:
//menu/#id[/option[#selected='selected']]
Iterate through the first list (in a beanshell processor or loop controller, for instance). Where an id appears in the second list, extract the selected value with:
//menu[#id='xxxx']/option[#selected='selected']/#value /*substitue xxxx with appropriate id*/
Where the id does not have a 'selected' value, extract the default value:
//menu/[#id='xxxx']/option[1]/#value /*substitue xxxx with appropriate id*/
(sorry if my xpath aren't completely accurate, I have written this from memory alone, but hopefully the breadcrumbs are there to follow)